Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!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.015 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'subject:Python': 0.06; '21,': 0.07; 'occurrences': 0.09; 'subject:language': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'cc:name:python list': 0.16; 'expression,': 0.16; 'scopes': 0.16; 'subject: \n ': 0.16; 'language': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'team,': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'sort': 0.25; 'header:In-Reply-To:1': 0.27; 'subject:list': 0.30; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'anyone': 0.31; 'fri,': 0.33; 'core': 0.34; 'maybe': 0.34; 'knowledge': 0.35; 'received:google.com': 0.35; "i'll": 0.36; 'pm,': 0.38; 'explain': 0.39; 'hope': 0.61; 'name': 0.63; 'different': 0.65; 'to:addr:gmail.com': 0.65; 'mar': 0.68; 'lack': 0.78; 'subject:this': 0.83; 'real-life': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=axeh8fHXoDvZtpkEpGuMrhCvaQfNwG/ZnHN1m1o7sAY=; b=wnJ3NaHCY3qzuIgAqObx5f22yVHP10kZ+cYdaNoz0KF8Dq9h35sXwhAFEHWG/DlJME Zbz+OEO9xFs/EbTWfPhr+eO5gwcGDg97cJBfAYSCovwJ8/8bbtEqv1OYdxC/UoJTXMCJ X7mGtLSmz76isn6/cIeGXrlev08J/YEZTsVAGZZb+HW8LclWDWZKH+uxEnhPqcoNiTMs gIzLhFMqbxHv1iUoqq5DYJni4Z1QihMmT8LHn/Hea2zLm7AuPbIFKidakefr1ta6Y1RZ O2ZNXaaJhALxsoulet65ZX9EbIJi8+GnwTA1T4QAN5EMku+L3tzu5pLmlUGQ5VcoOIDN hnog== MIME-Version: 1.0 X-Received: by 10.236.90.225 with SMTP id e61mr6249423yhf.15.1395963919876; Thu, 27 Mar 2014 16:45:19 -0700 (PDT) In-Reply-To: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> Date: Thu, 27 Mar 2014 16:45:19 -0700 Subject: Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) From: Dan Stromberg To: vasudevram Content-Type: text/plain; charset=ISO-8859-1 Cc: Python List 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: 9 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1395963929 news.xs4all.nl 2945 [2001:888:2000:d::a6]:44125 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:69226 On Fri, Mar 21, 2014 at 1:42 PM, vasudevram wrote: > Can anyone - maybe one of the Python language core team, or someone with knowledge of the internals of Python - can explain why this code works, and whether the different occurrences of the name x in the expression, are in different scopes or not? : > > x = [[1,2], [3,4], [5,6]] > [x for x in x for x in x] I'll give this +1 for playfulness, and -2 for lack of clarity. I hope no one thinks this sort of thing is good to do in real-life code.