Steven D'Aprano wrote: > On Sat, 30 May 2015 05:56 pm, Peter Otten wrote: > >> The following modification of the collections.Counter implementation >> >> https://hg.python.org/cpython/rev/fe4efc0032b5 >> >> was just checked in with the line >> >> result[elem] = 0 - count >> >> Does this have an advantage over the obvious >> >> result[elem] = -count >> >> ? > > > py> class Thingy: > ... def __neg__(self): > ... return [1, 2, 3, 4] > ... > py> -Thingy() > [1, 2, 3, 4] > py> 0 - Thingy() > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > TypeError: unsupported operand type(s) for -: 'int' and 'Thingy'
Hm, do you have an example of a Counter (or subclass) instance where the values are not int? -- https://mail.python.org/mailman/listinfo/python-list