Reputation: 11130
I have dictionary which has {key : []}
format. I need to prepare a list sorted based on the length of the value (length of the list). What's the best way to accomplish this?
Upvotes: 0
Views: 2567
Reputation: 165242
If you're looking for the values sorted by length, and assuming dict d
:
lists_by_length = sorted(d.values(), key=len)
Also see Sort a Python dictionary by value
Upvotes: 4