Mercurial > cpython-lru_cache-weakref
annotate Lib/UserList.py @ 5817:48b94de85bf3 legacy-trunk
Extensive changes by AMK.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Jul 1997 16:29:42 +0000 |
| parents | 3440777f0e65 |
| children | 125f21fde8c4 |
| rev | line source |
|---|---|
|
1416
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 # A more or less complete user-defined wrapper around list objects |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 class UserList: |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1416
diff
changeset
|
4 def __init__(self, list = None): |
|
1416
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 self.data = [] |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1416
diff
changeset
|
6 if list is not None: |
|
1416
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 if type(list) == type(self.data): |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 self.data[:] = list |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 else: |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 self.data[:] = list.data[:] |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 def __repr__(self): return repr(self.data) |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 def __cmp__(self, list): |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 if type(list) == type(self.data): |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 return cmp(self.data, list) |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 else: |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 return cmp(self.data, list.data) |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
17 def __len__(self): return len(self.data) |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 def __getitem__(self, i): return self.data[i] |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
19 def __setitem__(self, i, item): self.data[i] = item |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
20 def __delitem__(self, i): del self.data[i] |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
21 def __getslice__(self, i, j): |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 userlist = UserList() |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
23 userlist.data[:] = self.data[i:j] |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
24 return userlist |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
25 def __setslice__(self, i, j, list): |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
26 if type(list) == type(self.data): |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
27 self.data[i:j] = list |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
28 else: |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 self.data[i:j] = list.data |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
30 def __delslice__(self, i, j): del self.data[i:j] |
|
3628
3440777f0e65
added * and + operators
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
31 def __add__(self, list): |
|
3440777f0e65
added * and + operators
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
32 if type(list) == type(self.data): |
|
3440777f0e65
added * and + operators
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
33 return self.__class__(self.data + list) |
|
3440777f0e65
added * and + operators
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
34 else: |
|
3440777f0e65
added * and + operators
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
35 return self.__class__(self.data + list.data) |
|
3440777f0e65
added * and + operators
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
36 def __radd__(self, list): |
|
3440777f0e65
added * and + operators
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
37 if type(list) == type(self.data): |
|
3440777f0e65
added * and + operators
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
38 return self.__class__(list + self.data) |
|
3440777f0e65
added * and + operators
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
39 else: |
|
3440777f0e65
added * and + operators
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
40 return self.__class__(list.data + self.data) |
|
3440777f0e65
added * and + operators
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
41 def __mul__(self, n): |
|
3440777f0e65
added * and + operators
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
42 return self.__class__(self.data*n) |
|
3440777f0e65
added * and + operators
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
43 __rmul__ = __mul__ |
|
1416
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
44 def append(self, item): self.data.append(item) |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
45 def insert(self, i, item): self.data.insert(i, item) |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
46 def remove(self, item): self.data.remove(item) |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
47 def count(self, item): return self.data.count(item) |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 def index(self, item): return self.data.index(item) |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
49 def reverse(self): self.data.reverse() |
|
d6f6a1cb7d79
* test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
50 def sort(self, *args): apply(self.data.sort, args) |
