Discuss / Python / 这是为什么

这是为什么

Topic source

x = [1,2,3,4,5]

y = ['a','b','c','d','e']

p = {n:m for n in x for m in y}

print(p)

结果{1: 'e', 2: 'e', 3: 'e', 4: 'e', 5: 'e'}

x = [1,2,3,4,5]

y = ['a','b','c','d','e']

print(dict(zip(x, y)))

{1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e'}


  • 1

Reply