I prefer to do this in one line of code.
my_dict = {} my_dict[some_key] = my_dict.get(some_key, 0) + 1
from: https://stackoverflow.com/questions/473099/check-if-a-given-key-already-exists-in-a-dictionary-and-increment-it
No comments:
Post a Comment