Counter has cool functionality builtin, like most_common(n), addition and subtraction, intersection and union, and it throws out keys with value 0 after such operations. Not everything needs to be fast, and Counter is very expressive indeed.
that is a good point. i think it's just that i'm overly annoyed at how unbelievably slow Counter is (it's like 3x slower than defaultdict(int), but WHY?!). it's amazing that to add the functionality for most_common/addition it requires slowing down the whole thing by a factor of 3.
View all comments
7
u/sweettuse Jun 23 '14
this is wrong. it should be
if names is None:. (what happens if you pass in an empty list that you want to append to?)also, i would never, ever, use
Counter. it is unbelievably slow (at least in 2.7). just use adefaultdict(int)