A more elegant way to do this list comprehension?

Levi Self levi.r.self at gmail.com
Wed Jun 7 05:46:48 CEST 2006


This probably seems very trivial, maybe even a bit silly, but I was
wondering if someone has a better list comprehension that does the same
thing as this one:

>>> print [[[i]*i for i in range(1,9)][j][k] for j in range(8) for k in
range(j+1)]
[1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7,
7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8]

Thanks,
Levi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060606/c626c7c4/attachment.html>


More information about the Python-list mailing list