[issue14182] collections.Counter equality test thrown-off by zero counts

2012-08-08 Thread Stephen Webber

Stephen Webber added the comment:

Hmm, that is odd behavior indeed.

I think having keys that point to zero values is important for iterating over a 
set. For example:

 x = Counter(a=10, b=0)
 for k in set(x):
... x[k] += 1
... 
 x
Counter({'a': 11, 'b': 1})

is probably preferable to

 x = Counter(a=10, b=0)
 for k in set(x):
... x[k] += 1
... 
 x
Counter({'a': 11})

Perhaps to ensure intuitive behavior we could ensure that

 Counter(a = 3) + Counter(b = 0) == Counter(a = 3, b = 0)
True

by aggregating all keys into the new Counter object, even those with zero 
values? I would be happy to make such a patch, as it would be good experience 
for me to learn. Would this be an acceptable solution, and is there other odd 
behavior at work here?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14182
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14182] collections.Counter equality test thrown-off by zero counts

2012-08-05 Thread Stephen Webber

Stephen Webber added the comment:

This is intentional handling of non-existant variables, and is not resticted to 
'==' operations. Returning the value of a Counter parameter that has not yet 
been set returns 0 by default.

See the documentation here:
http://docs.python.org/library/collections.html

Counter objects have a dictionary interface except that they return a zero 
count for missing items instead of raising a KeyError:

Since this is intended behavior, I recommend this bug become closed.

--
nosy: +ForeverBacchus

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14182
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com