[Python-Dev] list comprehensions again...
Barry A. Warsaw
bwarsaw@beopen.com
Tue, 11 Jul 2000 23:23:00 -0400 (EDT)
>>>>> "SM" == Skip Montanaro <skip@mojam.com> writes:
BAW> Range literals I can see as being worth it. I wonder if
BAW> parallel for loops can't be handled more gracefully with a
BAW> function -- isn't it just a nice wrapper around a specific
BAW> call to map() anyway?
SM> I believe Thomas proposed range literals to avoid calling the
SM> range() function...
Right, and that seems totally cool to me. Simple syntax, clear
semantics.
SM> Regarding a wrapper around map(), you will need a pretty hairy
SM> wrapper, since you can do some pretty complex things with
SM> Greg's version of list comprehensions.
I meant the parallel for loops as a shortcut for map(). List
comprehensions do seem more powerful, however:
| print [s.strip() for s in spcs]
| print [3 * x for x in nums]
Cool so far.
| print [x for x in nums if x > 2]
Uh oh, starting to look like Perl...
| print [i, s for i in nums for s in strs]
| print [i, s for i in nums for s in [f for f in strs if "n" in f]]
Yow! No one will accuse Python of only having one way to do it
anymore! Even without the curse-word-symbols, I fear excessive scalp
exposing head-scratching when I see this in code.
-Barry