Last active
December 12, 2015 07:58
-
-
Save thisiswei/4740902 to your computer and use it in GitHub Desktop.
frequency
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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