Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'true,': 0.05; 'none,': 0.07; '[1,': 0.09; 'function:': 0.09; 'issue:': 0.09; 'subject:skip:c 10': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; '2],': 0.16; '[none,': 0.16; 'expression,': 0.16; 'ivan': 0.16; 'none.': 0.16; 'none]': 0.16; 'tuple': 0.16; 'wrote:': 0.18; 'message-----': 0.19; 'thanks.': 0.20; '>>>': 0.22; 'shell': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'fine': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'see,': 0.30; "i'm": 0.30; 'getting': 0.31; 'ok.': 0.31; 'yes.': 0.31; 'lists': 0.32; 'worked': 0.33; 'december': 0.35; 'subject:lists': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'skip:> 10': 0.36; 'var': 0.36; "i'll": 0.36; 'list': 0.37; 'email addr:python.org': 0.37; 'message-id:@gmail.com': 0.38; 'skip:[ 10': 0.38; 'skip:- 10': 0.38; 'subject:': 0.39; 'itself': 0.39; 're:': 0.63; 'kind': 0.63; 'email name:python-list': 0.65; 'within': 0.65; 'url:me': 0.69; 'received:109': 0.72 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:references:in-reply-to:subject:date:message-id :mime-version:content-type:content-transfer-encoding:thread-index :content-language; bh=IvqdygttQ2I9ZibXrTqTudslDowxyeLt6w4JUvRtJRA=; b=slPTEkn59af1IXkhUKlYLEcvyITDAT2LMu9Fe4yIDLIBes8DO8wWSNCwZQVn/5U2FX J11PGz7RFq+95Q+pGnWHPMGhRRFMpxX38Zx+BeaplHBP58KB0S2bWe1okvCIrPBpvECt usdASfhbMCgXbunE7fZTK3BV422asBF9g5ldKadOgX2plAw8fXjR3sg4fmLSSI1GBtrV WP1vKWwUFbkEabGgYTHbQWWe9Im/sBE+mzTh7k9XCYeFB3D4X+FUm7yYqbdNBs6O7vAE 11bE74GbqyaB4NR5nJvDmidA+vxQN6Ltnt55q378oRjWIoZobx8791/HO6GV20wMUlo9 pm9g== X-Received: by 10.180.107.193 with SMTP id he1mr17569886wib.27.1417966178356; Sun, 07 Dec 2014 07:29:38 -0800 (PST) From: "Ivan Evstegneev" To: "'Shiyao Ma'" References: <001a01d0122f$86b95480$942bfd80$@gmail.com> <20141207151749.GB32773@FuzzyHorror> In-Reply-To: <20141207151749.GB32773@FuzzyHorror> Subject: RE: Tuple of lists concatenation - function vs comprehension Date: Sun, 7 Dec 2014 17:28:33 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQKtx/3LUygJwXnTuEvBrvuxdstY8AGAvGtQmrzOSBA= Content-Language: en-us Cc: python-list@python.org 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: 69 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1417966680 news.xs4all.nl 2895 [2001:888:2000:d::a6]:59595 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:82062 Hi Shiyao, Now I see, that it was kind of dumb question... >>>>x = ([1, 2], [3, 4], [5, 6]) >>>>L = [] >>>[L.extend(i) for i in x] [None, None, None] BUT when I check L itself I'll see this one >>>L [1,2,3,5,6] Ok. Thanks. -----Original Message----- From: Shiyao Ma [mailto:i@introo.me] Sent: Sunday, December 7, 2014 17:18 To: Ivan Evstegneev Cc: python-list@python.org Subject: Re: Tuple of lists concatenation - function vs comprehension On 12/07, Ivan Evstegneev wrote: > Hello, > > When I have worked in Python shell (IDLE) I found this issue: > > >>>x = ([1, 2], [3, 4], [5, 6]) > >>>L = [] > >>>for I in x: > L.extend(i) > > >>>L > [1,2,3,4,5,6] > > But when I try to make comprehension using above expression, I get this: > > >>>x = ([1, 2], [3, 4], [5, 6]) > >>>L = [] > >>> [L.extend(i) for i in x] > [None, None, None] Yes. per the doc, list.extend() returns None. > > But this works fine within function: > > >>> def myfunc(): > x = ([1, 2], [3, 4], [5, 6]) > L = [] > [L.extend(i) for i in x] > print(L) > > >>>myfunc() > [1, 2, 3, 4, 5, 6] This is also so true, as you are print the var 'L'. > > The question is why I'm getting empty list while working with > comprehension in interactive console? You are also getting [None]*3 in comprenhension inside a function. -- Shiyao Ma http://introo.me