Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #43404
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Subject | Re: use a loop to create lists |
| Date | 2013-04-11 18:17 -0400 |
| Organization | > Bestiaria Support Staff < |
| References | (3 earlier) <5166A297.70104@th-nuernberg.de> <CAOjpqbM80RTXQsxgLJ9R_5X8uezWZQKcZ3F_fN8_vuq1D7_JoA@mail.gmail.com> <CAOjpqbMnZ_17iDj12qFqKU8sTEm7-QdYQAgi5T21R7k6kXFHgg@mail.gmail.com> <5166B345.8080200@th-nuernberg.de> <CAOjpqbOVME8dUXus9zBSLYCa+fJ8QsQYXd7sYw9RArfPHnHhKQ@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.492.1365718661.3114.python-list@python.org> (permalink) |
On Thu, 11 Apr 2013 16:11:13 +0200, Franz Kelnreiter
<kelnreiter@gmail.com> declaimed the following in
gmane.comp.python.general:
> On Thu, Apr 11, 2013 at 2:57 PM, Thomas Goebel <
> Thomas.Goebel@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)]}
>
Without the second set of square brackets, the result is a generator
expression/comprehension -- which came in a few versions after list
comprehensions did.
However, your position in locking the "n" inside the right hand, but
you need "n" on the left too...
Try moving the first [ to the beginning -- {["list....
(NO PROMISES -- I DIDN'T TEST}
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
use a loop to create lists martaamunar@gmail.com - 2013-04-10 01:40 -0700 Re: use a loop to create lists Chris Angelico <rosuav@gmail.com> - 2013-04-10 18:52 +1000 Re: use a loop to create lists Dave Angel <davea@davea.name> - 2013-04-10 08:36 -0400 Re: use a loop to create lists rusi <rustompmody@gmail.com> - 2013-04-10 08:31 -0700 Re: use a loop to create lists Thomas Goebel <Thomas.Goebel@ohm-hochschule.de> - 2013-04-10 15:55 +0200 Fwd: use a loop to create lists Franz Kelnreiter <kelnreiter@gmail.com> - 2013-04-11 14:11 +0200 Re: use a loop to create lists Thomas Goebel <Thomas.Goebel@ohm-hochschule.de> - 2013-04-11 14:57 +0200 Re: use a loop to create lists Chris Angelico <rosuav@gmail.com> - 2013-04-11 23:22 +1000 Re: Fwd: use a loop to create lists Thomas Goebel <Thomas.Goebel@ohm-hochschule.de> - 2013-04-11 15:43 +0200 Re: use a loop to create lists Franz Kelnreiter <kelnreiter@gmail.com> - 2013-04-11 16:11 +0200 Re: use a loop to create lists Thomas Goebel <Thomas.Goebel@ohm-hochschule.de> - 2013-04-11 16:33 +0200 Re: Fwd: use a loop to create lists Franz Kelnreiter <kelnreiter@gmail.com> - 2013-04-11 16:33 +0200 Re: use a loop to create lists Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-04-11 18:17 -0400
csiph-web