Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

Gotta be careful of that groupby. Using defaultdict has the pitfall that it continues to insert new keys when looking up missing keys after you're done grouping. Sometimes it's better to use a regular dict and setdefault during the grouping, ensuring that, after the grouping, missing lookups will properly raise KeyError.

In fact, AFAIK, Norvig made that specific mistake previously.



Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: