News for hackers. Stuff that matters.
Re:Python Idioms [pdf] by drakeandrews on Thursday January 30, 2014 @12:22PM (#7151863)
That example would surely be better as:

    something = myfunc(d['x']) if 'x' in d else None
Re:Python Idioms [pdf] by calroc on Thursday January 30, 2014 @02:31PM (#7152821)
In this form you perform the lookup twice: once to test 'x' in d and then again to actually get the value d['x']. Try clauses in Python are very inexpensive if they pass (don't raise an exception), so often the try..except version would be preferable.

In any event don't optimize prematurely and use a profiler rather than guessing if performance is an issue. ;-)

Re:Python Idioms [pdf] by prawks on Thursday January 30, 2014 @12:56PM (#7152106)
Doesn't this go against the Pythonic notion of handling exceptions rather than "looking before you leap"?
Re:Python Idioms [pdf] by wiredfool on Thursday January 30, 2014 @01:04PM (#7152184)
That looks like perl.