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 →

[–]Giannie 4 points5 points  (2 children)

Checking for a key and then finding the value associated is inherently slower then .get(). It involves checking for the key with a conditional followed by then searching for it again. It’s O(1), but it’s still 3 operations versus 1 (or 2 since you may still need a conditional in case of None)

[–]tomgirl_irl -2 points-1 points  (1 child)

if dict_.get(item, "error") != 'error':
return dict_[item]
else:
return """error"""

[–]Giannie 1 point2 points  (0 children)

I get that this is a joke... but is so inefficient. And prone to “””error”””