This is basically what I’m attempting to do, which isn’t working. Is there a way to single out a value of the dictionary and mathify it? For the sake of a crap example:
dictionaryNumbers = {'a':10,'b':10,'c':1,'d':1,'e':5,'f':1}
dictionaryNumbers['a'] += 5
#The goal would be dictionaryNumbers['a'] would equal 15.
EDIT:
Guys thanks for the feedback. It seems there was a flaw in the order in which I was calling the functions to modify the collection. I was printing the output before the math took place. Thanks again.
You are mostly doing it right, and your code is working fine:
but for any key not yet in the dict you’d have to test first (
if key not in dictionaryNumbers) or use.get():which gets old fast.
But I’d use a
collections.Counter()class instead:Advantages:
Counter(items_to_count).counter1 + counter2returns a newCounterwith all values summed.