【问题标题】:Tuple into Dictionary in Python [duplicate]元组到Python中的字典[重复]
【发布时间】:2011-07-22 15:18:01
【问题描述】:

可能重复:
Transform tuple to dict

如何更改元组列表,例如:

seq = [(1, 2), (3, 4), (5, 6)]

进入字典:

dicta = { 1:2, 2:4, 5:6 }

【问题讨论】:

    标签: python dictionary python-3.x tuples


    【解决方案1】:
    >>> seq = [(1, 2), (3, 4), (5, 6)]
    >>> dict(seq)
    {1: 2, 3: 4, 5: 6}
    

    python 不是很好吗:)

    Python Docs中所定义:

    The dict() constructor builds dictionaries directly from lists of key-value pairs stored as tuples.
    

    【讨论】:

      猜你喜欢
      • 2020-04-03
      • 2015-02-24
      • 2017-09-17
      • 2017-11-05
      • 2019-03-21
      • 1970-01-01
      • 1970-01-01
      • 2011-09-25
      • 1970-01-01
      相关资源
      最近更新 更多