How to count co-ocurrences with collections.Counter() in python?
问题 I learned about the collections.Counter() class recently and, as it's a neat (and fast??) way to count stuff, I started using it. But I detected a bug on my program recently due to the fact that when I try to update the count with a tuple, it actually treats it as a sequence and updates the count for each item in the tuple instead of counting how many times I inserted that particular tuple . For example, if you run: import collections counter = collections.Counter() counter.update(('user1',