python dict get index

Solutions on MaxInterview for python dict get index by the best coders in the world

we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
showing results for - "python dict get index"
Vincenzo
07 May 2017
1i = {
2	'foo':'bar',
3	'baz':'huh?'
4}
5
6#in python 3, you'll need to cast to list:
7# keys = list(i.keys())
8
9keys = i.keys()
10values = i.values()
11
12print(keys[values.index("bar")])
13# output: 'foo'