【发布时间】:2012-06-05 21:31:39
【问题描述】:
假设我有一个这样的字典列表:
dictionList = {1: {'Type': 'Cat', 'Legs': 4},
2: {'Type': 'Dog', 'Legs': 4},
3: {'Type': 'Bird', 'Legs': 2}}
使用 for 循环,我想遍历列表,直到我捕获一个字典,其中 Type 字段等于 "Dog"。
我最好的尝试是:
for i in dictionList:
if dictionList(i['Type']) == "Dog":
print "Found dog!"
但这给我带来了以下错误:
TypeError: 'int' object has no attribute '__getitem__'
关于如何正确执行此操作的任何想法?
【问题讨论】:
-
那不是字典列表,那是字典的字典
标签: python list dictionary for-loop