我正在尝试使用for循环在嵌套字典中添加项。该项应该在内部字典中,因此它显示为项'Aggressive': True
之后的项,并且在每个内部字典中,即'Gold-crested Toucan'
和'Pearlescent Kingfisher'
rarebirds = {
'Gold-crested Toucan': {
'Height (m)': 1.1,
'Weight (kg)': 35,
'Aggressive': True},
'Pearlescent Kingfisher': {
'Height (m)': 0.25,
'Weight (kg)': 0.5,
'Aggressive': False},
}
#my most recent attempt below, although I've tried using .update as well as i and j dics within the loop
for key in rarebirds:
rarebirds[key]['Seen'] == False
输出为KeyError: 'Seen'
对于这个简单问题的建议将不胜感激
rarebirds.keys()
迭代键李>rarebirds[key]['Seen'] == False
。double equals正在尝试执行相等检查,这导致keyError
李>相关问题 更多 >
编程相关推荐