简体   繁体   中英

finding list element in list that contains dictionary by key

{ 'id1': [{'id2': [messageobject, messageobject1]}, {}], 'next_id': [{'example_key': messageobj},{'example_key2': messageobj}]

how do i find the list index by search of the key"id2" in list id1 The index of the element

The provided dictionary does not work as is, but this is how you will get the index:

for i, dict_ in enumerate(d.get('id1')):
  if 'id2' in dict_:
    print("Fount at index: " + str(i))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM