我试图使用lambda查找字典中的键列表
输入
3
qwe 123
asd 456
zxc 789
qwe
ghj
zxc
输出
qwe = 123
Not Found
zxc = 789
代码如下:
d = {}
n = int(input())
d = dict((input().lower()).split() for _ in range(n))
List = d.keys()
L = []
for _ in range (n):
name = (input().strip()).lower()
L.append(name)
output = map(lambda x,y :x if x in y else False,List,L)
result = list(output)
for i in result:
if i !=False:
print('{}={}'.format(i,d[i]))
else:
print("Not Found")
没有任何输出。任何人都可以帮助
答案 0 :(得分:0)
您正在尝试将第十二行的列表abc附加到您尚未定义的行上。用L代替abc可以修复您的代码。