list comprehension question

J Kenneth King james at agentultra.com
Wed May 6 09:48:51 EDT 2009


Emile van Sebille <emile at fenx.com> writes:

> On 5/5/2009 9:15 AM J Kenneth King said...
>
>> List comprehensions can make a reader of your code apprehensive
>> because it can read like a run-on sentence and thus be difficult to
>> parse. The Python documentation discourages their use and I believe
>> for good reason.
>
> Can you provide a link for this?  I'd like to see specifically what's
> being discouraged, as I'd be surprised to find routine usage frowned
> upon.
>
> Emile

http://docs.python.org/tutorial/datastructures.html#nested-list-comprehensions


"If you’ve got the stomach for it, list comprehensions can be
nested. They are a powerful tool but – like all powerful tools – they
need to be used carefully, if at all."

and

"In real world, you should prefer builtin functions to complex flow
statements."



More information about the Python-list mailing list