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.



-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to