what is the difference between one-line-operation and 2-line-operation
oyster
lepto.python at gmail.com
Mon Apr 25 10:13:56 EDT 2016
for a simple code
[code]
vexList = [1, 2, 3]
print('vexList', list(vexList))
vexList=map(lambda e: e+1, vexList)
print('vexList', list(vexList))
vexList = list(vexList)
print('vexList', list(vexList))
vexList=map(lambda e: e*2,vexList)
print('vexList', list(vexList))
[/code]
py27 says
[quote]
('vexList', [1, 2, 3])
('vexList', [2, 3, 4])
('vexList', [2, 3, 4])
('vexList', [4, 6, 8])
[/quote]
but py34 says
[quote]
vexList [1, 2, 3]
vexList [2, 3, 4]
vexList []
vexList []
[/quote]
if I change the above code in to one line
[code]
vexList = [1, 2, 3]
print('vexList', list(vexList))
vexList=list(map(lambda e: e+1, vexList))
print('vexList', list(vexList))
vexList=map(lambda e: e*2,vexList)
print('vexList', list(vexList))
[/code]
then py27 and py34 get same verList
[quote]
('vexList', [1, 2, 3])
('vexList', [2, 3, 4])
('vexList', [4, 6, 8])
[/quote]
I found 'filter' function behaves likely
I found
type(map(lambda e: e, vexList)) is <type 'list'> in py2
type(map(lambda e: e, vexList)) is <class 'map'> in py3
so, what produces this difference between py2 and py3 in nature? is
there more examples? where can I find the text abiut his difference?
Thanks
More information about the Python-list
mailing list