title: How to remove duplicates from a list in only one method?
body: <p>I want to remove duplicates in the list, but append elements in the list when there are no duplicates in the existing data but only in the <code>extend()</code> method, not in the <code>append()</code> method (because I will treat an added list in the <code>append()</code> method as one distinctive datum).</p>
  <pre><code>from collections import UserList
  
  class Ulist(UserList):
      def __init__(self, list_=[]):
           UserList.__init__(self)
           self.list_=list_
  
      def __add__(self, another):
          for i in another:
              if i in self:
                  raise ValueError
                  print(&quot;Duplicated Data!&quot;)
              else:
                  return UserList.__add__(self, another)
  
      def append(self, another):
          if another in self:
              raise ValueError
              print(&quot;Duplicated Data!&quot;)
          else:
              return UserList.append(self, another)
  
      def extend(self, another):
          for x in another:
              if x in self:
                  print(&quot;Duplicated Data! Erase the Duplicated Data&quot;)
                  listList=UserList.extend(self, another)
                  listList=list(set(listList))
                  return listList
                         
              else:
                  return UserList.extend(self, another)
  </code></pre>
  <p>And this is the error message when I work with the list having an element duplicated with the existing list. I don't understand how <code>TypeError: 'NoneType' object is not iterable</code> applies. How do I correct the <code>extend()</code> method?</p>
  <pre><code>&gt;&gt;&gt; l=Ulist()
  &gt;&gt;&gt; l.__add__([98])
  []
  &gt;&gt;&gt; l.append('kim')
  &gt;&gt;&gt; l.extend(['lee', 'park', 'choi'])
  &gt;&gt;&gt; l.append(['kim', 'jeong', 'kang'])
  &gt;&gt;&gt; l.extend(['lee', 'kim', 'joo'])
  Duplicated Data! Erase the Duplicated Data
  Traceback (most recent call last):
    File &quot;&lt;pyshell#110&gt;&quot;, line 1, in &lt;module&gt;
      l.extend(['lee', 'kim', 'joo'])
    File &quot;C:\Users\소현\AppData\Local\Programs\Python\Python38-32\User_list.py&quot;, line 28, in extend
      listList=list(set(listList))
  TypeError: 'NoneType' object is not iterable
  </code></pre>