(Oct-08-2018, 11:10 AM)DeaD_EyE Wrote:results = collections.defaultdict(int)Read the docs about defaultdict and test it.
You can do thinks like:
results['key_which_does_not_exist'] = 1 #or for counting results['key_which_does_not_exist'] += 1 # if the key does not exist, it's 0
I think that
collections.Counter
will be a better choice. One of the advantages of Counter
is that you may apply arithmetic operations between objects of that type
Test everything in a Python shell (iPython, Azure Notebook, etc.)
- Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
- Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
- You posted a claim that something you did not test works? Be prepared to eat your hat.