Wednesday, April 11, 2012

how to get the 10 most frequent strings in a list in python

I have a list that has 93 different strings. I need to find the 10 most frequent strings and the return must be in order from most frequent to least frequent.



mylist = ['"and', '"beware', '`twas', 'all', 'all', 'and', 'and', 'and', 'and', 'and', 'and', 'and', 'and', 'and', 'and', 'and', 'and', 'and', 'arms', 'as', 'as', 'awhile', 'back', 'bandersnatch', 'beamish', 'beware', 'bird', 'bite', 'blade', 'borogoves', 'borogoves', 'boy', 'brillig']
# this is just a sample of the actual list.




No comments:

Post a Comment