MCPcopy Create free account
hub / github.com/ActiveState/code / __mul__

Method __mul__

recipes/Python/578612_Counter_class/recipe-578612.py:257–267  ·  view source on GitHub ↗

Returns new bag of same type multiplied by factor. >>> d = {1: 2, 2: 4, 3: -9} >>> IntegerBag(d) * -1 {1: -2, 2: -4, 3: 9} >>> Bag(d) * -1 {}

(self, factor)

Source from the content-addressed store, hash-verified

255 return self
256
257 def __mul__(self, factor):
258 """Returns new bag of same type multiplied by factor.
259
260 >>> d = {1: 2, 2: 4, 3: -9}
261 >>> IntegerBag(d) * -1
262 {1: -2, 2: -4, 3: 9}
263 >>> Bag(d) * -1
264 {}
265 """
266 #XXX should perhaps use explicit IntBag in case derived class needs parameters -- or use copy()???
267 return self.__class__(self).__imul__(factor)
268
269 def _size(self):
270 """Returns sum of absolute value of item counts in bag.

Callers

nothing calls this directly

Calls 1

__imul__Method · 0.45

Tested by

no test coverage detected