3 ms·
What about thing = my_dict.get(key) if thing is None: ...
by 390iuwjhf 4y ago
What about
thing = my_dict.get(key)
if thing is None:
...
- tremon 4y agoyes, my_dict.get() is my preferred solution too, if I can come up with a sensible default value or action. Otherwise, I do my_dict[key] without try/except. But I'm not sure if that's just a style preference or if there's a large performance difference in Python.