字典绑定两个不同的列表


a=[2,1]
b=['app','applied']
f={}
for id in a:
   for name in b:
     f[id]=name

输出{2:'app', 1: 'app'}在我生成另一个 for 循环之后

for c in f:
   print(c)

然后输出是 2,1 不显示值 我试过了

for c,k in f:
   print(c,k)
return error

但我需要键和值 请帮助我

我尝试了很多次无法得到解决方案。我在字典中绑定了两个不同的列表,但只得到键值,但值应该只有一个值来绑定键。请帮助我

试试函数zip

a = [2, 1]
b = ['app', 'applied']
f = dict(zip(a,b))
print(f.items())

最新更新