Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #43258

Re: use a loop to create lists

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.140
X-Spam-Level *
X-Spam-Evidence '*H*': 0.73; '*S*': 0.01; 'list...': 0.07; 'subject:create': 0.09; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'string,': 0.24; 'header:In-Reply-To:1': 0.27; 'skip:g 30': 0.30; 'message- id:@mail.gmail.com': 0.30; 'fine,': 0.31; 'names.': 0.31; 'lists': 0.32; 'received:209.85': 0.35; 'something': 0.35; 'subject:lists': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'list': 0.37; 'list.': 0.37; 'received:209': 0.37; 'lists.': 0.38; 'to:addr :python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'range': 0.61; 'name': 0.63; 'here': 0.66; 'positions': 0.67; 'containing': 0.69; 'presumably': 0.84; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=e0zmZehd1lqBoj7uyAvk/n4z8jBB0VwQViPRLjxXJIo=; b=mhmlXjV3mFMkmsYJ9lN27ZlmKEagJj7bR9tcZYDbDbhspc5OjpL9QfuuzH8rqwiF0v LvWHNNpQdsqJxSJ30IpwhVmy9J2kbSUJQlt3tENdpIMWljsU7TWjxm5rVGOJktzQ9iD7 Nc3yq8YKL0XOJBCzzxMBrD57VmFJvP356xsC+X57tluhew79YZZabGQFBw5JxSXqpnEF Bci7wGCH4wWnEinTQfMgOaKY0MwmCfKlpjTRGaVZFdB+d9N0gJfERDYn93QT7Ok6sPuT X6uV7ya8EmoeekUyeuxHrbQJhKpaDXkBOSkx48x4O/0R+iGU9qWYzK8rraH7EZ+57f+o PHWg==
MIME-Version 1.0
X-Received by 10.52.67.164 with SMTP id o4mr656774vdt.42.1365583959543; Wed, 10 Apr 2013 01:52:39 -0700 (PDT)
In-Reply-To <4c47da9e-c632-4855-98a7-0506d8013046@googlegroups.com>
References <4c47da9e-c632-4855-98a7-0506d8013046@googlegroups.com>
Date Wed, 10 Apr 2013 18:52:39 +1000
Subject Re: use a loop to create lists
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.401.1365583968.3114.python-list@python.org> (permalink)
Lines 22
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1365583968 news.xs4all.nl 2665 [2001:888:2000:d::a6]:51042
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:43258

Show key headers only | View raw


On Wed, Apr 10, 2013 at 6:40 PM,  <martaamunar@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=[]
> for i in range (20):
>   ("list_"+i)=[]   #These would be the name of the list...
>   global_list.append("list_"+i)

They don't need unique names. Just use the same name inside the loop:

global_list=[]
for i in range(20):
  current_list=[]  # Presumably you do something with it here
  global_list.append(current_list)

That'll work fine, and you can reference the lists by their positions
in global_list.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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