If I have a list with some nested dictionaries each containing the same keyset and value type set.
list = [{'a': 1, 'b': 2.0, 'c': 3.0},
{'a': 4, 'b': 5.0, 'c': 6.0},
{'a': 7, 'b': 8.0, 'c': 9.0}]
What is the most pythonic way to return the list index of the first of occurrence of 5.0 within the 'b' dictionary keys, or None if nothing is found?
I know I could iterate and search manually:
#with the list above...
result = None
for dict in list:
if dict['b'] == 5.0:
result = list.index(dict)
break
print result
#(prints 1)
#as another example, same code but searching for a different value in 'b'
result = None
for dict in list:
if dict['b'] == 6.0:
result = list.index(dict)
break
print result
#(prints None)
But this seems rather cumbersome. Thank you in advance.