[Chicago] A list comprehension???

kirby urner kirby.urner at gmail.com
Tue May 5 02:28:32 CEST 2015


Lets remember also about dict and set comprehensions.

List comprehensions get all the press.


On Mon, May 4, 2015 at 5:02 PM, Vivek Pabani <vpabani at hawk.iit.edu> wrote:

> This worked for me :
>
> [sum(xrange(0, 2*i, 2)) for i in xrange(1, 11)]
>
>
These are indeed giving the same lists:

print([(4*n**2 + 4*n)//4 for n in range(50)])
print([sum(range(0, 2*i, 2)) for i in range(1, 50)])

[0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, ...]
[0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, ...]

Kirby
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20150504/a0f10107/attachment.html>


More information about the Chicago mailing list