Python: get a dict from a list based on something inside the dict

前端 未结 7 668
自闭症患者
自闭症患者 2020-11-30 23:56

I need to be able to find an item in a list (an item in this case being a dict) based on some value inside that dict. The structure o

7条回答
  •  春和景丽
    2020-12-01 00:20

    Worked only with iter() for me:

    my_item = next(iter(item for item in my_list if item['id'] == my_unique_id), None)
    

提交回复
热议问题