Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #107604
| From | oyster <lepto.python@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | what is the difference between one-line-operation and 2-line-operation |
| Date | 2016-04-25 22:13 +0800 |
| Message-ID | <mailman.78.1461593638.32212.python-list@python.org> (permalink) |
| References | <CACW-qXU_b9G3016m12FgqgUEhGE-QkioiXacQOCAHrRrVzbQPg@mail.gmail.com> |
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
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
what is the difference between one-line-operation and 2-line-operation oyster <lepto.python@gmail.com> - 2016-04-25 22:13 +0800 Re: what is the difference between one-line-operation and 2-line-operation Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-04-25 17:42 +0300
csiph-web