I have a list of dictionaries as follows:
myList=[{'id':1,'key1':'a','key2':'b'},{'id':8,'key1':'c','key2':'d'},
{'id':6,'key1':'a','key2':'p'}]
To find the index of an element, I am currently executing the following statement:
print myList.index({'id':8,'key1':'c','key2':'d'})
which returns 1
However, I would like to do something like this:
print myList.index({'id':8})
must return 1
source
share