[英]print sum of 2 dictionary values based on key
我的代码如下:
{'Bug Out Bag': ['q', 0.25, 100], 'XM': ['q', 0.25, 10]}
print('{}'.format(float(addition1)+float(addition2)) )
我收到一个错误:
addition1 = coins_in_the_bag[0]
KeyError: 0
谢谢!
coins_in_the_bag = {'Bug Out Bag': ['q', 0.25, 100], 'XM': ['q', 0.25, 10]}
coins_in_the_bag
是一个dict
。 使用诸如
>>> coins_in_the_bag['Bug Out Bag']
# ['q', 0.25, 100]
>>> coins_in_the_bag['XM']
# ['q', 0.25, 10]
另外, coins_in_the_bag['Bug Out Bag']
将返回一个列表。 警惕呼叫float
而不是整个列表
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.