【问题标题】:finding list element in list that contains dictionary by key在包含字典的列表中查找列表元素
【发布时间】:2020-08-21 23:44:43
【问题描述】:
{ 'id1': [{'id2': [messageobject, messageobject1]}, {}], 'next_id': [{'example_key': messageobj},{'example_key2': messageobj}]

如何通过在列表 id1 中搜索键“id2”来找到列表索引 元素的索引

【问题讨论】:

    标签: python python-3.x list dictionary indexing


    【解决方案1】:

    提供的字典不能按原样工作,但这是您获取索引的方式:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-04
      • 2012-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多