Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1a.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'output': 0.05; 'subject:Python': 0.06; 'interpreter.': 0.07; 'modified': 0.07; 'odd': 0.07; 'test,': 0.07; 'string': 0.09; '"if': 0.09; 'iterate': 0.09; 'subject:language': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'language.': 0.14; '(int': 0.16; '24,': 0.16; 'assignment?': 0.16; 'binding,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'iterating': 0.16; 'looping': 0.16; 'mean,': 0.16; 'notation': 0.16; 'subject: \n ': 0.16; 'syntactic': 0.16; 'utterly': 0.16; 'language': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'bit': 0.19; "python's": 0.19; 'stack': 0.19; 'cc:addr:python.org': 0.22; 'certainly': 0.24; 'filtering': 0.24; 'passes': 0.24; 'mon,': 0.24; 'cc:2**0': 0.24; "i've": 0.25; 'source': 0.25; 'equivalent': 0.26; 'header:In- Reply-To:1': 0.27; 'function': 0.29; 'chris': 0.29; '[1]': 0.29; 'am,': 0.29; '[2]': 0.30; 'statement': 0.30; 'subject:list': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'too.': 0.31; '"do': 0.31; '(maybe': 0.31; '25,': 0.31; 'everywhere': 0.31; 'languages': 0.32; 'themselves': 0.32; 'level.': 0.33; 'not.': 0.33; 'basic': 0.35; 'something': 0.35; 'operations': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'done': 0.36; 'list': 0.37; 'level': 0.37; 'being': 0.38; 'whatever': 0.38; 'pm,': 0.38; 'though,': 0.39; 'sure': 0.39; 'called': 0.40; 'how': 0.40; 'even': 0.60; 'ian': 0.60; 'most': 0.60; 'simple': 0.61; 'name': 0.63; 'high': 0.63; 'kind': 0.63; 'provide': 0.64; 'situation': 0.65; 'talking': 0.65; 'mar': 0.68; 'prompt': 0.68; 'statement,': 0.68; 'miss': 0.74; 'repeat': 0.74; 'subject:this': 0.83; 'bare': 0.84; 'goto': 0.84; 'boxes': 0.91; 'boxes,': 0.91; 'to:none': 0.92; 'imagine': 0.93 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=4P7qXk8hpwXY+bstP5Yic3SZWfDe90QRgLoI3ntXJso=; b=Zbrw3RHkbQMDMzBJVoxQKgvemDj1fsC8uRQWmausb3A4fbpH4gwT2SCm9rpzUUmVkl F96szGvYX1jr+uvBe57DKlI1sU1++IWGhY9+qVyau2wqLP2vp4DfmefGcq5kdxaPx+Qv D+kIAla3dN9lQC1x9uMrFYE5meFZXBwEcyl5/CKW6LPImo+roGp+hr2MpUiqDKzs+Wbn RL40YDeKyF7p1uyBsmXS3KICSBY+sIzIMPswCQiIq/uWvD+kpufcRYb2vQnXcR4deK7p Q4qvUSqCBq+/Eh9lDOfXLVTiPMpvaUfj+r4AXAu9RYxEyD+blVa4HWb7qhlZEHUhpJ7S nOWg== MIME-Version: 1.0 X-Received: by 10.68.201.10 with SMTP id jw10mr73758640pbc.25.1395691039580; Mon, 24 Mar 2014 12:57:19 -0700 (PDT) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87bnwv2a5v.fsf@elektro.pacujo.net> <53303b8a$0$29994$c3e8da3$5496439d@news.astraweb.com> Date: Tue, 25 Mar 2014 06:57:19 +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 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: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1395691042 news.xs4all.nl 2926 [2001:888:2000:d::a6]:44140 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:68901 On Tue, Mar 25, 2014 at 6:42 AM, Ian Kelly wrote: > On Mon, Mar 24, 2014 at 1:12 PM, Chris Angelico wrote: >> Incidentally, I've often modified my loop counter, in C or REXX or any >> other language. About the only situation where I actually miss it in >> Python, though, is iterating over a list and mutating the list on the >> way through; and even that can often be done in other ways (maybe a >> list comp, filtering out some of the elements?). It's amazing how >> something can be so utterly fundamental (I mean, come ON! Who can >> imagine a language with no equivalent of the basic "do i=1 to 10" >> (REXX) or "for (int i=0;i<10;++i)" (C++) loop???) and yet so >> dispensable. > > I'm not sure "fundamental" is the right word. A for loop is just a > while loop with some syntactic sugar. For that matter, a while loop > is just a structured goto... Of course, and function calls are just stack operations and gotos too. That's not what makes it fundamental - I'm talking at a source code level. Can you imagine a high level language without a simple notation for variable assignment? Certainly not. [1] Variable assignment, name binding, whatever you call it, is fundamental. Some kind of structured looping is also pretty critical; you don't see languages that force you to use bare goto everywhere and call themselves "high level". [2] Every high level language also needs some way to iterate over numbers. Most of them provide it as an intrinsic; Python happens to do it as a foreach over an easily-constructed iterable. ChrisA [1] DeScribe Macro Language would borderline-fail this test if I called it a HLL. It has "SET something TO somevalue". But DML is about on the level of Python's "dis.dis" output - assembly language for a byte-code interpreter. [2] DML passes this test, even. It has a block IF/ELSE/END IF statement, and a REPEAT/END REPEAT for looping, with the loop condition being provided by a statement "EXIT WHEN condition" that's like Python's "if condition: break". Mind you, it also provides language-level support for message boxes, including prompt boxes (ask the user to provide a string or integer), so it's a bit of an odd duck.