The problem was a simple indentation typo. Now if we were trying to write some more efficient/pythonic code, we could just use collections.Counter
which is a specialized dictionary type which counts items. Your code can be shortened and optimized:
from collections import Counter
inv = Counter({'gold coin': 42, 'rope': 1})
inv.update(['gold coin', 'dagger', 'gold coin', 'gold coin', 'ruby'])
print(inv)
result:
Counter({'gold coin': 45, 'rope': 1, 'dagger': 1, 'ruby': 1})