Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #82058

Tuple of lists concatenation - function vs comprehension

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!fdn.fr!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <webmailgroups@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'none,': 0.07; '[1,': 0.09; 'function:': 0.09; 'issue:': 0.09; 'subject:skip:c 10': 0.09; 'python': 0.11; 'def': 0.12; '2],': 0.16; '[none,': 0.16; 'expression,': 0.16; 'none]': 0.16; 'help.': 0.21; '>>>': 0.22; 'shell': 0.22; 'fine': 0.24; 'question': 0.24; 'this:': 0.26; "i'm": 0.30; 'getting': 0.31; 'worked': 0.33; 'subject:lists': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'charset:us- ascii': 0.36; 'thanks': 0.36; 'list': 0.37; 'message- id:@gmail.com': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'within': 0.65; 'received:109': 0.72
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:mime-version:content-type :content-transfer-encoding:thread-index:content-language; bh=4J90pWuJ9JKWO2Fk5lxYFW59HKcQMAR3m+aHZs5SvIg=; b=jDv+ERE+2mgeYbmJj2EbTh5qDpEba4gM1sHTK+MoAYKF+pMBTKNimd53CiW3ZgV+P/ qZaPgXafpQgYAnInrC7qSJaqDw5JMZMiku4S+LKGkKDTVne6xKzSKVDzxmhLdVE5D5yc fQkEyHdTm7tGmhyVFkxHS/8v1n4O3rFmJnrIoIldMAF9WzpblByROgUk6ANOngBjBokv Gokz2i7P2Lv3UkWHTa3GYiensdNUY/sRf0kQ8ih7FbWPUdqV+Tv1uatNbTQKBiGMoa1S yxeRseKMdgacZhmMxgyREasNkagUoD11bLdZqaivJi5+ERs60QEisuocZbUKUI/LYJvb cJNQ==
X-Received by 10.180.19.193 with SMTP id h1mr17764255wie.10.1417964915476; Sun, 07 Dec 2014 07:08:35 -0800 (PST)
From "Ivan Evstegneev" <webmailgroups@gmail.com>
To <python-list@python.org>
Subject Tuple of lists concatenation - function vs comprehension
Date Sun, 7 Dec 2014 17:07:31 +0200
MIME-Version 1.0
Content-Type text/plain; charset="us-ascii"
Content-Transfer-Encoding 7bit
X-Mailer Microsoft Outlook 14.0
Thread-Index AdASLhNIRyl4k6G4S4KveJ4DpYKNoQ==
Content-Language en-us
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.16670.1417964924.18130.python-list@python.org> (permalink)
Lines 39
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1417964924 news.xs4all.nl 2893 [2001:888:2000:d::a6]:48077
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:82058

Show key headers only | View raw


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]

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]

The question is why I'm getting empty list while working with comprehension
in interactive console? 

Thanks for your help.

Ivan.


Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Tuple of lists concatenation  -  function vs comprehension "Ivan Evstegneev" <webmailgroups@gmail.com> - 2014-12-07 17:07 +0200

csiph-web