Paul's Programming Notes PostsRSSGithub

None Can Be A Key In Python Dicts

None is hashable, so it works as a dictionary key like any other immutable value.

>>> my_dict = {None: "value"}
>>> my_dict[None]
'value'

This is handy when you’re grouping rows by a column that can be NULL, because the NULL group gets None for its key and you don’t have to invent a sentinel value to stand in for it.