A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2006-July/066890.html below:

[Python-Dev] 2.5 and beyond

[Python-Dev] 2.5 and beyondGreg Ewing greg.ewing at canterbury.ac.nz
Sat Jul 1 08:15:29 CEST 2006
Giovanni Bajo wrote:

>>>>a = []
>>>>for i in range(10):
> 
> ...     a.append(lambda: i)
> ...
> 
>>>>print [x() for x in a]
> 
> [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]
> 
> This subtle semantic of lambda is quite confusing, and still forces people to
> use the "i=i" trick.

This has *nothing* to do with the semantics of lambda!
It's because Python's for-loop doesn't put its control
variable in a new scope, the way Scheme's equivalent
construct does.

*That's* what needs to be addressed to fix this problem.
I've made a suggestion about that before, but Guido
rejected it, so I won't repeat it here.

--
Greg

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4