New submission from Ethan Furman:

According to the docs [1]:

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

Which a simple test confirms:

--> Counter()['b']
0

However, if the key is present but set to zero, equality fails:

--> Counter() == Counter(b=0)
False

It is my thought that a Counter with all its keys set to zero is as empty as a 
Counter with no keys:

--> c1 = Counter()
--> c2 = Counter(a=0, b=0, c=0)
--> for item in c2.keys():
...   assert c2[item] == c1[item]
(no execption raised)


[1] https://docs.python.org/2/library/collections.html#collections.Counter

----------
messages: 228111
nosy: ethan.furman
priority: normal
severity: normal
status: open
title: Counter with no keys does not compare equal to Counter with keys which 
zero value
type: behavior
versions: Python 2.7, Python 3.4, Python 3.5

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue22533>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to