Convert two lists into a dictionary

前端 未结 18 2604
囚心锁ツ
囚心锁ツ 2020-11-21 04:35

Imagine that you have:

keys = [\'name\', \'age\', \'food\']
values = [\'Monty\', 42, \'spam\']

What is the simplest way to produce the foll

18条回答
  •  自闭症患者
    2020-11-21 05:13

    You may also try with one list which is a combination of two lists ;)

    a = [1,2,3,4]
    n = [5,6,7,8]
    
    x = []
    for i in a,n:
        x.append(i)
    
    print(dict(zip(x[0], x[1])))
    

提交回复
热议问题