Re: Fwd: use a loop to create lists

2013-04-11 Thread Franz Kelnreiter
On Thu, Apr 11, 2013 at 3:43 PM, Thomas Goebel < thomas.goe...@ohm-hochschule.de> wrote: > ... > > I get a syntax error, as I exepected (Python 2.6.4 (r264:75708, Oct 26 > > 2009, 08:23:19)). > > Sorry Franz, > > as you are using python 2.6 you have to use > > d1 = dict(('list_' + str(i), []) for

Re: use a loop to create lists

2013-04-11 Thread Thomas Goebel
* On 11/04/2013 16:11, Franz Kelnreiter wrote: > On Thu, Apr 11, 2013 at 2:57 PM, Thomas Goebel < > thomas.goe...@ohm-hochschule.de> wrote: > >> ... >> Which is the same as: >> f = {'list_' + str(n):[m for m in range(3)] for n in range(3)} >> > [...] > But didnt you miss square brackets: > > f =

Re: use a loop to create lists

2013-04-11 Thread Franz Kelnreiter
On Thu, Apr 11, 2013 at 2:57 PM, Thomas Goebel < thomas.goe...@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 expressio

Re: Fwd: use a loop to create lists

2013-04-11 Thread Thomas Goebel
* On 11/04/2013 14:11, Franz Kelnreiter wrote: > On Thu, Apr 11, 2013 at 1:46 PM, Thomas Goebel wrote: > >> global_list = {'_'.join(['list', str(i)]):[] for i in range(20)} > > Thanks for your explanation, I think I know what you want to do and I would > very much like to understand your code in d

Re: use a loop to create lists

2013-04-11 Thread Chris Angelico
On Thu, Apr 11, 2013 at 10:57 PM, Thomas Goebel wrote: > [a for a in range(3)] > > will return a list > [0, 1, 2] Simplification possible: That's the same as: list(range(3)) > f = {'list_' + str(n):[m for m in range(3)] for n in range(3)} Meaning that this can be simplified too: f = {'list_'

Re: use a loop to create lists

2013-04-11 Thread Thomas Goebel
* On 11/04/2013 14:11, Franz Kelnreiter wrote: > On Thu, Apr 11, 2013 at 1:46 PM, Thomas Goebel wrote: >> >> the difference between your and my code is that >> >> global_list = {'_'.join(['list', str(i)]):[] for i in range(20)} >> >> creates a dict 'global_list' which has 20 keys named from 'list_0

Fwd: use a loop to create lists

2013-04-11 Thread Franz Kelnreiter
-- Forwarded message -- From: Franz Kelnreiter Date: Thu, Apr 11, 2013 at 2:09 PM Subject: Re: use a loop to create lists To: thomas.goe...@ohm-hochschule.de On Thu, Apr 11, 2013 at 1:46 PM, Thomas Goebel < thomas.goe...@ohm-hochschule.de> wrote: > * On 11/04/2013 13:

Re: use a loop to create lists

2013-04-11 Thread Thomas Goebel
* On 10/04/2013 10:40, martaamu...@gmail.com wrote: > Hi! > > I would like to create a list containing lists. I need each list to > have a differente name and i would like to use a loop to name the > list. > [...] > global_list=[] > for i in range (20): > ("list_"+i)=[] #These would be the n

Re: use a loop to create lists

2013-04-10 Thread rusi
On Apr 10, 1:40 pm, martaamu...@gmail.com wrote: > Hi! > > I would like to create a list containing lists. I need each list to have a > differente name and i would like to use a loop to name the list. But as the > name, is a string, i cannot asign it to a value... how can I do that?? > > global_l

Re: use a loop to create lists

2013-04-10 Thread Dave Angel
On 04/10/2013 04:40 AM, martaamu...@gmail.com wrote: Hi! I would like to create a list containing lists. I need each list to have a differente name and i would like to use a loop to name the list. But as the name, is a string, i cannot asign it to a value... how can I do that?? global_list=[

Re: use a loop to create lists

2013-04-10 Thread Chris Angelico
On Wed, Apr 10, 2013 at 6:40 PM, wrote: > Hi! > > I would like to create a list containing lists. I need each list to have a > differente name and i would like to use a loop to name the list. But as the > name, is a string, i cannot asign it to a value... how can I do that?? > > > global_list=[

use a loop to create lists

2013-04-10 Thread martaamunar
Hi! I would like to create a list containing lists. I need each list to have a differente name and i would like to use a loop to name the list. But as the name, is a string, i cannot asign it to a value... how can I do that?? global_list=[] for i in range (20): ("list_"+i)=[] #These would