sarat
sarat

Reputation: 11130

Python: Sorting dictionary based on value (list)

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

Answers (1)

Yuval Adam
Yuval Adam

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

Related Questions