Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python OrderedDict get a key index of

Can OrderedDict get a key position?

is like list of index()

test = ['a', 'b', 'c', 'd', 'e']
test.index('b') # return 1
like image 359
XiaoXiao Avatar asked Jan 24 '26 10:01

XiaoXiao


1 Answers

just one line program. such as:

print(list(your_ordered_dict).index('your_key'))

Maybe you can use lambda,like this line program:

f = lambda ordered_dict, key: list(ordered_dict).index(key)

Good luck.

like image 157
Karl Doenitz Avatar answered Jan 27 '26 00:01

Karl Doenitz