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


Groups > comp.lang.python > #82058 > unrolled thread

Tuple of lists concatenation - function vs comprehension

Started by"Ivan Evstegneev" <webmailgroups@gmail.com>
First post2014-12-07 17:07 +0200
Last post2014-12-07 17:07 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

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

#82058 — Tuple of lists concatenation - function vs comprehension

From"Ivan Evstegneev" <webmailgroups@gmail.com>
Date2014-12-07 17:07 +0200
SubjectTuple of lists concatenation - function vs comprehension
Message-ID<mailman.16670.1417964924.18130.python-list@python.org>
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.


[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web