Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'programmer': 0.03; 'subject:Python': 0.06; 'element': 0.07; '[1,': 0.09; 'subject:language': 0.09; 'things,': 0.09; 'way:': 0.09; 'cc:addr :python-list': 0.11; 'python': 0.11; 'def': 0.12; '"create': 0.16; '"global"': 0.16; '24,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'sense,': 0.16; 'statement.': 0.16; 'structs': 0.16; 'subject: \n ': 0.16; 'elements': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'stack': 0.19; 'cc:addr:python.org': 0.22; 'byte': 0.24; 'mon,': 0.24; 'cc:2**0': 0.24; 'source': 0.25; 'push': 0.26; 'header:In-Reply-To:1': 0.27; 'compared': 0.30; 'subject:list': 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'loads': 0.31; 'actual': 0.34; 'created': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'useful': 0.36; 'two': 0.37; 'list,': 0.38; 'pm,': 0.38; 'little': 0.38; 'does': 0.39; 'sure': 0.39; 'how': 0.40; 'truly': 0.60; 'become': 0.64; 'more': 0.64; 'between': 0.67; 'mar': 0.68; 'manner.': 0.74; 'subject:this': 0.83; 'imperative.': 0.84; 'precious': 0.84; 'to:none': 0.92 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:cc :content-type; bh=FqU5plZwfJPDiDwSQp/EOD+oVZFeVE4RsM1ux8mruKo=; b=yc4CrnKFdzajhl/CkA/6Kn/xE5QW0A6i7CMdYcae8X+oqxvdnb015AlkqvVsyavFXp 1iT8P/WTpG0LchvplCBJKLBPeS0rqU6XSGtp7U7PtCDVJ9rl65w5MnVbFPItnjuJl8en 0DyPy+JZiolOUb346lUQIeLZJeDKSMzcc9nJ8yFffVN775N2Jdfac9qqK2fxF/LQ1W+/ BEP03cOCNOa3QgetHd5aUslyLs24SWCW1qUYdOZ+zYNtubOBjmDJyx29KTsMG5wRipxk aEJgjYd48r+e3573wfgIRQj9ik0e4CF/aMeI4L9z0updpQJilBciHinWRXp+3g9EsuBe 75/Q== MIME-Version: 1.0 X-Received: by 10.66.11.66 with SMTP id o2mr967863pab.142.1395631934008; Sun, 23 Mar 2014 20:32:14 -0700 (PDT) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <9edb4ea0-5faf-4369-8021-48afa9800a34@googlegroups.com> Date: Mon, 24 Mar 2014 14:32:13 +1100 Subject: Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1395631937 news.xs4all.nl 2851 [2001:888:2000:d::a6]:41001 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:68845 On Mon, Mar 24, 2014 at 1:35 PM, Rhodri James wrote: > I'm not sure I would. I look at that line of code and think of it as > "Create a list...", very much in an imperative manner. Then again, compared > with C structs and typedefs and actual honest-to-God type declarations, > there's precious little in Python I would consider truly declarative. By the way: Python does have a difference between "declarative" and "imperative". def f(): # Imperative global x # Declarative x += 1 # Imperative Declaratives control things, imperatives become byte code. Everything in the byte code is imperative. "LOAD_GLOBAL" means "fetch this global and put it on the stack". "INPLACE_ADD" means "iadd the top two stack elements and push the result onto the stack". "STORE_GLOBAL" means "pop the top stack element and store it in this global". Very very imperative, and there's none of that created by the "global" statement. So in that sense, yes, "x = [1, 2, 3]" is imperative; it loads three constants, builds a list, and stores it. But digging into the byte code isn't really helpful; it's much more useful to look at the source code and how the programmer thinks about it. ChrisA