python dict get key by index code example
Example 1: how to retrieve dictionary values in python by index
a_dictionary = {"a": 1, "b": 2, "c":3}
keys_list = list(a_dictionary)
key = keys_list[0]
print(key)
Example 2: python dict get index
i = {
'foo':'bar',
'baz':'huh?'
}
#in python 3, you'll need to cast to list:
# keys = list(i.keys())
keys = i.keys()
values = i.values()
print(keys[values.index("bar")])
# output: 'foo'