Something is rotten in Denmark...
Martin Manns
mmanns at gmx.net
Tue May 31 17:14:56 EDT 2011
On Tue, 31 May 2011 01:48:05 -0500
harrismh777 <harrismh777 at charter.net> wrote:
> >>> fs=[]
> >>> fs = [(lambda n: i + n) for i in range(10)]
> >>> [fs[i](1) for i in range(10)]
> [10, 10, 10, 10, 10, 10, 10, 10, 10, 10] <=== not good
>
> ( that was a big surprise! . . . )
> ( let's try it another way . . . )
After being confused I figured out it is a 3.x example:
----
$ python
Python 2.6.6 (r266:84292, Apr 20 2011, 11:58:30)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> fs=[]
>>> fs = [(lambda n: i + n) for i in range(10)]
>>> [fs[i](1) for i in range(10)]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
----
$ python3.1
Python 3.1.3 (r313:86834, Nov 28 2010, 11:28:10)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> fs=[]
>>> fs = [(lambda n: i + n) for i in range(10)]
>>> [fs[i](1) for i in range(10)]
[10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
----
Is this fixed automatically by 2to3?
Martin
More information about the Python-list
mailing list