【问题标题】:Convert a List of Lists into a dictionary? in python将列表列表转换为字典?在蟒蛇
【发布时间】:2022-06-17 22:31:48
【问题描述】:

我想将列表列表转换为字典,其中每个子列表都是字典中的键值 例如

array = [[a,b],[c,d],[e,f]]

我想要这样的输出

dict = { a:b,c:d,e:f }

【问题讨论】:

    标签: python python-3.x dictionary


    【解决方案1】:

    使用dictionary comprehension

    dct = {x[0]: x[1] for x in array}
    

    【讨论】:

      猜你喜欢
      • 2017-04-23
      • 2021-10-13
      • 2015-07-23
      • 1970-01-01
      • 2014-01-20
      • 2020-05-23
      • 2019-06-11
      相关资源
      最近更新 更多