Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'operator': 0.03; 'read.': 0.03; 'from:addr:yahoo.co.uk': 0.04; 'subject:Python': 0.06; '21,': 0.07; '[1,': 0.09; 'boring': 0.09; 'dan': 0.09; 'lawrence': 0.09; 'occurrences': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:language': 0.09; 'things,': 0.09; 'python': 0.11; 'wrote': 0.14; 'language.': 0.14; 'expression,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reinvent': 0.16; 'scopes': 0.16; 'strange,': 0.16; 'subject: \n ': 0.16; 'using,': 0.16; 'language': 0.16; 'wrote:': 0.18; 'code.': 0.18; '>>>': 0.22; 'import': 0.22; 'team,': 0.22; 'header:User-Agent:1': 0.23; '---': 0.24; 'sort': 0.25; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; "doesn't": 0.30; 'subject:list': 0.30; 'code': 0.31; 'anyone': 0.31; 'another': 0.32; 'fri,': 0.33; 'programmers': 0.33; 'core': 0.34; 'maybe': 0.34; 'knowledge': 0.35; 'subject: (': 0.35; 'subject:lists': 0.35; 'add': 0.35; "i'll": 0.36; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'explain': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'easy': 0.60; 'simple,': 0.60; 'hope': 0.61; 'free': 0.61; 'no.': 0.61; 'viruses': 0.61; "you're": 0.61; 'name': 0.63; 'protection': 0.63; 'real': 0.63; 'such': 0.63; 'our': 0.64; 'more': 0.64; 'different': 0.65; 'mar': 0.68; 'antivirus': 0.68; 'lack': 0.78; 'subject:this': 0.83; 'real- life': 0.84; 'received:2': 0.84; 'lists:': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: Howto flaten a list of lists was (Explanation of this Python language feature) Date: Fri, 28 Mar 2014 22:12:33 +0000 References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: host-2-98-198-214.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 In-Reply-To: X-Antivirus: avast! (VPS 140328-1, 28/03/2014), Outbound message X-Antivirus-Status: Clean 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: 46 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1396044784 news.xs4all.nl 2966 [2001:888:2000:d::a6]:37495 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:69290 On 28/03/2014 21:56, Mark H Harris wrote: > 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. Strange, I thought Dan Stromberg wrote the above. > > No. This has to be a better way to flatten lists: > > >>> from functools import reduce > > >>> import operator as λ > > >>> reduce(λ.add, l) > [1, 2, 3, 4, 5, 6, 7, 8, 9] > Why reinvent yet another way of flattening lists, particulary one that doesn't use the far more sensible:- from operator import add As for the stupid symbol that you're using, real programmers don't give a damn about such things, they prefer writing plain, simple, boring code that is easy to read. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com