List comprehension confusion...

David Eppstein eppstein at ics.uci.edu
Sun Feb 2 12:11:46 EST 2003


In article <mailman.1044182705.19650.python-list at python.org>,
 Andy Jewell <andy at wild-flower.co.uk> wrote:

> I personally find list comprehensions quite obfuscated - it's one of the few 
> constructs within python which is not immediately obvious to a beginner or 
> non-pythonist.

For me they were extremely understandable at first glance.
I think it's a question of familiarity with certain mathematical 
notations, e.g. [ x^2 for x in range(y) ] is very similar to
{ x^2 | 0 <= x < y }.  But if you're familiar with programming but not 
mathematics, it may be more natural to express this as a loop...

-- 
David Eppstein       UC Irvine Dept. of Information & Computer Science
eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/




More information about the Python-list mailing list