Tampa
Tampa

Reputation: 78422

Python - If given dictionary create a list of keys in order of the values

I have a dictionary that looks like the below.

ex1_pattern = {'ex':0,'country':1,'dow':2,'hod':3,'adx':4,'vid1':5} 

I would like to create a lists of the keys e.g.

ex1_pattern.keys()

but..I would like the list to be in the order of the ranks. e.g.:

[ex,country,dow,hod,adx,vid1]

What is the most time efficient means to do that?

Upvotes: 2

Views: 107

Answers (1)

eumiro
eumiro

Reputation: 213115

sorted(ex1_pattern, key=ex1_pattern.get)

Upvotes: 10

Related Questions