【发布时间】:2020-11-08 09:47:36
【问题描述】:
我有一个字典列表,还有一个 cmets 元素,如何在打印这个列表时打印带有注释的数字,
- 示例评论
- 另一个示例评论
这是我在 python 中的代码
entries = [{'First Name': 'Sher', 'Last Name': 'Khan', 'Age': '22', 'Telephone': '2989484'},
{'First Name': 'Ali', 'Last Name': 'Khan', 'Age': '22', 'Telephone': '398439'},
{'First Name': 'Talha', 'Last Name': 'Khan', 'Age': '22', 'Telephone': '3343434', 'comments': []}]
search = input("type your search: ")
if search in [person['Last Name'] for person in entries]:
for person in entries:
if person["Last Name"] == search:
print("Here are the records found for your search")
for e in person:
if e == "comments":
for comment in person["comments"]:
print(comment)
else:
print(e, ":", person[e])
else:
print("There is no record found as you search Keyword")
【问题讨论】:
标签: python list loops dictionary for-loop