Advertisement
here2share

# listbycount.py

Feb 22nd, 2017
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.22 KB | None | 0 0
  1. # listbycount.py
  2.  
  3. mylist = [1, 1, 6, 1, 3, 3, 4, 4, 4, 4, 5, 2, 2, 2, 2]
  4. mydict = {}
  5. for i in set(mylist):
  6.     mydict[i] = mylist.count(i)
  7.  
  8. t = sorted(mydict.items(), key=lambda value: value[1], reverse=True)
  9.  
  10. print t
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement