Skip to content

Instantly share code, notes, and snippets.

@thisiswei
Last active December 12, 2015 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thisiswei/4740902 to your computer and use it in GitHub Desktop.
Save thisiswei/4740902 to your computer and use it in GitHub Desktop.
frequency
from collections import Counter
from collections import defaultdict
def frequency1(lst):
return [(lst.count(s), s) for s in set(lst)]
def frequency2(lst):
return dict((s, lst.count(s))
for s in set(lst))
def frequency3(lst):
d = defaultdict(int)
for s in lst:
d[s] += 1
return d
def frequency4(lst):
return Counter(lst)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment