aris
0
Q:

python dictionary get element by index

# To get value from index in a list:
x = ["Foo", "Bar", "Roblox"]

print(x[0]) # Output: Foo
2
value_at_index = dic.values()[index]
0
# To return the index of the first occurence of element x in lst
ind = lst.index(x)
1
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'
0

New to Communities?

Join the community