Advertisement
here2share

# list_dict_by_len.py

Jan 20th, 2020
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.27 KB | None | 0 0
  1. # list_dict_by_len.py
  2.  
  3. # sorting dictionary by length of values
  4. d = {"three": [(4,1),(4,2)], "two": [(1,1),(1,2),(1,3)], "four": [(3,1)], "one": [(2,1),(2,2),(2,3),(2,4)]}
  5. r = [k for k in sorted(d, key=lambda k: len(d[k]), reverse=True)]
  6. for i in r:
  7.     print i+'\t', d[i]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement