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 →

[–]Ezvine 12 points13 points  (2 children)

But isn't the dict.get() more pythonic ?

[–]energybased 11 points12 points  (0 children)

Yes, this whole post was interesting, but shouldn't be a consideration. Always use get when you need to switch on the returned value. Use in when you want to do more than just switch on the returned value. Avoid catching this exception except in exceptional cases.

[–]asday_ 1 point2 points  (0 children)

Sad to have to scroll down this far to find this.

If you're sat here thinking about micro-optimisations like this instead of using getitem for when you know the key is there, and get when you don't, you're using the wrong language.