Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # list_dict_by_len.py
- # sorting dictionary by length of values
- 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)]}
- r = [k for k in sorted(d, key=lambda k: len(d[k]), reverse=True)]
- for i in r:
- print i+'\t', d[i]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement