我有一个名为 clients_list 的列表,其中包含如下字典:
clients_list =
[
{'John Guy': [28, '03171992', 'Student']},
{'Bobby Jones': [22, '02181982', 'Student']},
{'Claire Eubanks': [18, '06291998', 'Student']},
]
我如何使用输入的答案检查是否有人在此列表中?我试过代码
elif answer in clients_list:
print(f'{answer} is in our database.')
但似乎不能正常工作。
最佳答案
试试这个
clients_list = [{'John Guy': [28, '03171992', 'Student']},
{'Bobby Jones': [22, '02181982', 'Student']},
{'Claire Eubanks': [18, '06291998', 'Student']}]
c= 'John Guy'
for item in clients_list:
if c in item:
print c + 'is in our database.'
break
关于python检查字典是否在列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49025765/