1 """A more or less complete user-defined wrapper around list objects."""
6 if initlist
is not None:
8 if type(initlist) == type(self.
data):
9 self.
data[:] = initlist
10 elif isinstance(initlist, UserList):
11 self.
data[:] = initlist.data[:]
13 self.
data = list(initlist)
21 def __cast(self, other):
22 if isinstance(other, UserList):
return other.data
32 i =
max(i, 0); j =
max(j, 0)
33 return self.__class__(self.
data[i:j])
35 i =
max(i, 0); j =
max(j, 0)
36 if isinstance(other, UserList):
37 self.
data[i:j] = other.data
38 elif isinstance(other, type(self.
data)):
39 self.
data[i:j] = other
41 self.
data[i:j] = list(other)
43 i =
max(i, 0); j =
max(j, 0)
46 if isinstance(other, UserList):
47 return self.__class__(self.
data + other.data)
48 elif isinstance(other, type(self.
data)):
49 return self.__class__(self.
data + other)
51 return self.__class__(self.
data + list(other))
53 if isinstance(other, UserList):
54 return self.__class__(other.data + self.
data)
55 elif isinstance(other, type(self.
data)):
56 return self.__class__(other + self.
data)
58 return self.__class__(list(other) + self.
data)
60 if isinstance(other, UserList):
61 self.
data += other.data
62 elif isinstance(other, type(self.
data)):
65 self.
data += list(other)
68 return self.__class__(self.
data*n)
73 def append(self, item): self.data.append(item)
74 def insert(self, i, item): self.data.insert(i, item)
75 def pop(self, i=-1):
return self.data.pop(i)
76 def remove(self, item): self.data.remove(item)
77 def count(self, item):
return self.data.count(item)
78 def index(self, item):
return self.data.index(item)
80 def sort(self, *args): apply(self.data.sort, args)
82 if isinstance(other, UserList):
83 self.data.extend(other.data)
85 self.data.extend(other)