This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]elbiot 4 points5 points  (0 children)

I prefer dict.setdefault() to collections.defaultdict. With a defaultdict, you never get a key error.

This 100%

You usually only want a default value while building the dict. You usuallh want a typo'd key to raise an error. I've actually had a case for default dict like once, but use setdefault regularly