[Python-ideas] except expression

Chris Angelico rosuav at gmail.com
Wed Feb 19 02:16:04 CET 2014


On Wed, Feb 19, 2014 at 11:58 AM, Jan Kaliszewski <zuo at chopin.edu.pl> wrote:
>     sum((x[3] except IndexError: 0)
>         for x in list_of_tuples)

Really, I don't think this example is all that bad even without the parens:

sum(x[3] except IndexError: 0 for x in list_of_tuples)

Compare:

sum(x[3] if len(x)>3 else 0 for x in list_of_tuples)

which is a roughly-comparable LBLY check doing the same thing, and
which doesn't need parens. If you want 'em, go ahead, put 'em in, but
it's not horrible without them.

ChrisA


More information about the Python-ideas mailing list