I just noticed that while the docs say that "Counts are allowed to be any integer value including zero or negative counts", collections.Counter doesn't perform any check on the types of count values. Instead, non-numerical values will lead to strange behaviour or exceptions later on: >>> c = collections.Counter({'a':'3', 'b':'20', 'c':'100'}) >>> c.most_common(2) [('a', '3'), ('b', '20')] >>> c+c Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/local/hagenf/lib/python3.1/collections.py", line 467, in __add__ if newcount > 0: TypeError: unorderable types: str() > int() I'd prefer Counter to refuse non-numerical values right away as the present behaviour may hide bugs (e.g. a forgotten string->int conversion). Any opinions? (And what about negative values or floats?) - Hagen
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4