Lazy list/range comprehensions

"Jérôme M. Berger" jeberger at free.fr
Sun Oct 3 10:50:11 PDT 2010


bearophile wrote:
> 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
> 
	Why didn't you write the second like this to keep it functional:
result2 = dict (map (lambda x: (x, x*x), xrange (20)))

		Jerome
-- 
mailto:jeberger at free.fr
http://jeberger.free.fr
Jabber: jeberger at jabber.fr

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20101003/1ea267db/attachment.pgp>


More information about the Digitalmars-d mailing list