python dict: get vs setdefault

Your two examples do the same thing, but that doesn’t mean get and setdefault do. The difference between the two is basically manually setting d[key] to point to the list every time, versus setdefault automatically setting d[key] to the list only when it’s unset. Making the two methods as similar as possible, I ran from … Read more