1.1 --- a/lib/__builtins__/list.py Mon Apr 03 01:36:47 2017 +0200
1.2 +++ b/lib/__builtins__/list.py Mon Apr 03 01:37:06 2017 +0200
1.3 @@ -113,6 +113,27 @@
1.4 self.extend(other)
1.5 return self
1.6
1.7 + def __mul__(self, other):
1.8 +
1.9 + "Replicate this sequence 'other' times."
1.10 +
1.11 + return self._mul(list(self), other)
1.12 +
1.13 + def __imul__(self, other):
1.14 +
1.15 + "Replicate this list 'other' times."
1.16 +
1.17 + return self._mul(self, other)
1.18 +
1.19 + def _mul(self, l, other):
1.20 +
1.21 + "Replicate 'l' 'other' times."
1.22 +
1.23 + while other > 1:
1.24 + l.extend(self)
1.25 + other -= 1
1.26 + return l
1.27 +
1.28 def __str__(self):
1.29
1.30 "Return a string representation."
2.1 --- a/tests/list.py Mon Apr 03 01:36:47 2017 +0200
2.2 +++ b/tests/list.py Mon Apr 03 01:37:06 2017 +0200
2.3 @@ -57,6 +57,9 @@
2.4 c = a + b
2.5 print c # [1, 2, 3, 4, 5, 6]
2.6
2.7 +a2 = a * 2
2.8 +print a2 # [1, 2, 3, 4, 1, 2, 3, 4]
2.9 +
2.10 # Test removal.
2.11
2.12 print c.pop() # 6