Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.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.027 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:create': 0.09; '"n"': 0.16; 'brackets,': 0.16; 'brackets:': 0.16; 'did.': 0.16; 'goebel': 0.16; 'patience': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'shorthand': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'url:home': 0.24; 'versions': 0.24; 'second': 0.26; 'header:X-Complaints-To:1': 0.27; 'didnt': 0.31; 'beginning': 0.33; 'subject:lists': 0.35; 'but': 0.35; '+0200,': 0.36; "didn't": 0.36; 'charset:us-ascii': 0.36; 'list': 0.37; 'thank': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'moving': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'expression': 0.60; 'first': 0.61; 'thomas': 0.65; 'miss': 0.74; 'square': 0.74; 'as:': 0.81; 'hand,': 0.93; 'received:108': 0.93; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: use a loop to create lists Date: Thu, 11 Apr 2013 18:17:32 -0400 Organization: > Bestiaria Support Staff < References: <4c47da9e-c632-4855-98a7-0506d8013046@googlegroups.com> <51656F6A.5040103@th-nuernberg.de> <5166A297.70104@th-nuernberg.de> <5166B345.8080200@th-nuernberg.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-108-73-118-117.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 3.3/32.846 X-No-Archive: YES 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1365718661 news.xs4all.nl 2685 [2001:888:2000:d::a6]:49451 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:43404 On Thu, 11 Apr 2013 16:11:13 +0200, Franz Kelnreiter 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/