from collections import defaultdict
def mode(iterable):
counts = defaultdict(int)
for item in iterable:
counts[item] += 1
return max(counts, key = counts.get)
Should be reasonably fast (for pure-python), though could eat up a lot of memory on an iterable contaning large items.
No comments:
Post a Comment