Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'operator': 0.03; 'subject:Python': 0.06; '21,': 0.07; '[1,': 0.09; 'dan': 0.09; 'subject:language': 0.09; 'subject:How': 0.10; 'python': 0.11; 'expression,': 0.16; 'received:10.20.200': 0.16; 'received:charter.net': 0.16; 'scopes': 0.16; 'subject: \n ': 0.16; 'subject:?)': 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; 'sort': 0.25; 'header:In-Reply-To:1': 0.27; 'subject:list': 0.30; 'code': 0.31; 'anyone': 0.31; 'fri,': 0.33; 'received:10.20': 0.33; 'core': 0.34; 'maybe': 0.34; 'knowledge': 0.35; 'subject: (': 0.35; 'subject:lists': 0.35; 'skip:> 10': 0.36; "i'll": 0.36; 'list': 0.37; 'received:10': 0.37; 'message- id:@gmail.com': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'hope': 0.61; 'name': 0.63; 'different': 0.65; 'received:96': 0.65; 'mar': 0.68; 'lack': 0.78; 'subject:this': 0.83; 'real-life': 0.84; 'lists:': 0.91 X-Authority-Analysis: v=2.0 cv=Q7eKePKa c=1 sm=1 a=EBsYl1X+Lq2xj3QUCo3MmA==:17 a=zewopLiEtFcA:10 a=2eC17GywufEA:10 a=nDghuxUhq_wA:10 a=IkcTkHD0fZMA:10 a=pGLkceISAAAA:8 a=BbWEGnyQ8XcKhXzfd94A:9 a=QEXdDO2ut3YA:10 a=MSl-tDqOz04A:10 a=EBsYl1X+Lq2xj3QUCo3MmA==:117 Date: Fri, 28 Mar 2014 17:00:27 -0500 From: Mark H Harris User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 Newsgroups: comp.lang.python To: python-list@python.org Subject: How to flatten a list of lists was (Explanation of this Python language feature?) References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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: , Message-ID: Lines: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1396044046 news.xs4all.nl 2830 [2001:888:2000:d::a6]:52291 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:69287 On 3/27/14 6:45 PM, Dan Stromberg 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. > You might try this to flatten a list of lists: >>> from functools import reduce >>> import operator >>> import operator as λ >>> reduce(λ.add, l) [1, 2, 3, 4, 5, 6, 7, 8, 9] >>> marcus