我有下面的字典:
freelancers = {'name': 'freelancing Shop', 'brian': 70, 'black knight': 20,
'biccus diccus': 100, 'grim reaper': 500, 'minstrel': -15}如果找到包含'shop‘这个词的值,我希望我的for语句在所有dictionary..and中循环。打印出来。有什么办法吗?
这显然不起作用,值可以是字符串、int等等。
for key, value in freelancers.items():
if 'Shop' in value:
print(f"Welcome to {value}")发布于 2020-05-26 13:30:49
您需要添加类型检查。
for key, value in freelancers.items():
if isinstance(value, str) and 'Shop' in value:
print(f"Welcome to {value}")https://stackoverflow.com/questions/62023212
复制相似问题