Python sorting dictionary keys into a list by values -


this question has answer here:

i have dictionary say:

red : 2 blue : 1 yellow : 9 black : 9 white : 5 

i need generate list of keys sorted values:

[blue, red, white, black, yellow] 

is there neatish way of doing this?

i have had around, , there similar questions, seem sorting values or keys only.

you can use sorted function dict.get key :

sorted(your_dictionary.keys(), key=your_dictionary.get)

or says in comments can use :

sorted(your_dictionary, key=your_dictionary.get)


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -