Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ce84920

Browse files
committed
added * and + operators
1 parent 48bdbfc commit ce84920

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

Lib/UserList.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ def __setslice__(self, i, j, list):
2828
else:
2929
self.data[i:j] = list.data
3030
def __delslice__(self, i, j): del self.data[i:j]
31+
def __add__(self, list):
32+
if type(list) == type(self.data):
33+
return self.__class__(self.data + list)
34+
else:
35+
return self.__class__(self.data + list.data)
36+
def __radd__(self, list):
37+
if type(list) == type(self.data):
38+
return self.__class__(list + self.data)
39+
else:
40+
return self.__class__(list.data + self.data)
41+
def __mul__(self, n):
42+
return self.__class__(self.data*n)
43+
__rmul__ = __mul__
3144
def append(self, item): self.data.append(item)
3245
def insert(self, i, item): self.data.insert(i, item)
3346
def remove(self, item): self.data.remove(item)

0 commit comments

Comments
 (0)