Lazy list/range comprehensions
bearophile
bearophileHUGS at lycos.com
Sun Oct 3 10:21:44 PDT 2010
SiegeLord:
> Back when I was programming Python I found the array comprehension syntax unreadable, so I always used the map equivalent.
Python devs have introduced list comps only after asking about their "ergonomicity" level to many people. And for most of those people code like this:
result1 = [x * x + 5 for x in xrange(10)]
result2 = {x: x * x for x in xrange(20)}
Allows the programmer to see code purpose better and create higher-level mental chunks than code like:
result1 = map(lambda x: x * x + 5, xrange(10))
result2 = {}
for x in xrange(20):
result2[x] = x * x
Bye,
bearophile
More information about the Digitalmars-d
mailing list