Convert a list to a dictionary in Python

前端 未结 12 2143
無奈伤痛
無奈伤痛 2020-11-22 04:14

Let\'s say I have a list a in Python whose entries conveniently map to a dictionary. Each even element represents the key to the dictionary, and the following o

12条回答
  •  一个人的身影
    2020-11-22 05:10

    try below code:

      >>> d2 = dict([('one',1), ('two', 2), ('three', 3)])
      >>> d2
          {'three': 3, 'two': 2, 'one': 1}
    

提交回复
热议问题