index from dictionary python code example
Example 1: create dict of value to index from list python
>>> lst = ['A','B','C']
>>> {k: v for v, k in enumerate(lst)}
{'A': 0, 'C': 2, 'B': 1}
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'