Hello

I read in a course that class UserList from module
collections can be used to create our own custom list

Example

>>> from collections import UserList
>>> class MyList(UserList):
...     def head(self):
...         return self.data[0]
...     def queue(self):
...         return self.data[1:]
...
>>> l = MyList([1, 2, 3])
>>> l.append(4)
>>> l
[1, 2, 3, 4]
>>> l.head()
1
>>> l.queue()
[2, 3, 4]


But I can do exactly the same without UserList


>>> class MyList(list):
        def head(self):
            return self[0]
        def queue(self):
            return self[1:]

>>> l = MyList([1, 2, 3])
>>>  l.append(4)
>>> l
[1, 2, 3, 4]
>>> l.head()
1
>>> l.queue()
[2, 3, 4]


So what UserList is used for ?
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to