我不明白您应该如何在多维字典中引用嵌套字典。我正在尝试将两个词典中的physA和physD的值合并到一个新的总字典中,但是不知道该如何工作。有人可以告诉我如何对抗嵌套值吗?
from collections import Counter
bronzeSword = {"Bronze Sword":Counter({"physA":4,"physD":1})}
ironSword = {"Iron Sword":Counter({"physA":5,"physD":2})}
total = bronzeSword + ironSword
print("Physical Attack:",total["physA"],"Physical Defence:",total["physD"])
答案 0 :(得分:0)
没关系,当我发布问题后,它立刻就击中了我。
from collections import Counter
bronzeSword = {"Bronze Sword":Counter({"physA":4,"physD":1})}
ironSword = {"Iron Sword":Counter({"physA":5,"physD":2,"magD":-1})}
total = bronzeSword["Bronze Sword"] + ironSword["Iron Sword"]
print("Physical Attack:",total["physA"],"Physical Defence:",total["physD"])