use a loop to create lists

Franz Kelnreiter kelnreiter at gmail.com
Thu Apr 11 10:11:13 EDT 2013


On Thu, Apr 11, 2013 at 2:57 PM, Thomas Goebel <
Thomas.Goebel at ohm-hochschule.de> wrote:

> ...
> Which is the same as:
> f = {'list_' + str(n):[m for m in range(3)] for n in range(3)}
>

Thomas, thank you for your patience and your long explanation! Now I
understand better this shorthand expression of one single 'pythonic' ;)
line.
But didnt you miss square brackets:

f = {'list_' + str(n):[[m for m in range(3)] for n in range(3)]}

??
Otherwise the code wont work for me...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130411/2015af0a/attachment.html>


More information about the Python-list mailing list