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: 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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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=[] > 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