Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!newsfeed.eweka.nl!feeder3.eweka.nl!81.171.88.15.MISMATCH!eweka.nl!lightspeed.eweka.nl!194.134.4.91.MISMATCH!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.049 X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; 'syntax': 0.04; '(python': 0.07; 'subject:create': 0.09; 'python': 0.11; 'received:141': 0.14; '2.6.4': 0.16; '[])': 0.16; 'goebel': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'header:User-Agent:1': 0.23; 'header:In-Reply-To:1': 0.27; 'code': 0.31; '2009,': 0.31; 'maybe': 0.34; 'subject:lists': 0.35; 'but': 0.35; '2.6': 0.36; 'thanks': 0.36; 'detail': 0.37; 'too': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'subject:Fwd': 0.61; 'here:': 0.62; 'header:Message-Id:1': 0.63; 'thomas': 0.65; 'header:Reply-To:1': 0.67; 'stated': 0.69; 'reply-to:no real name:2**0': 0.71; '2013': 0.98 Date: Thu, 11 Apr 2013 15:43:09 +0200 From: Thomas Goebel Organization: Technische Hochschule Nuernberg User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130328 Thunderbird/17.0.5 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Fwd: use a loop to create lists References: <4c47da9e-c632-4855-98a7-0506d8013046@googlegroups.com> <51656F6A.5040103@th-nuernberg.de> <5166A297.70104@th-nuernberg.de> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Thomas.Goebel@ohm-hochschule.de 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: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1365687787 news.xs4all.nl 2566 [2001:888:2000:d::a6]:55657 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:43369 * 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 detail - maybe I am too stupid - > but when I execute the value part of your code construct: > > [a for a in range(20)] for i in range(20) > > 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 i in range(3)) d2 = dict(('list_' + str(i), [m for m in range(3)]) for i in range(3)) like stated here: http://stackoverflow.com/questions/1747817/python-create-a-dictionary-with-list-comprehension