question about scope

Steven D'Aprano steve at REMOVETHIScyber.com.au
Thu Feb 16 17:35:43 EST 2006


On Thu, 16 Feb 2006 15:18:29 +0000, John Salerno wrote:

> What's an example of a local scope without 
> having a function definition? Loops and if statements, perhaps?

List comprehensions: [2*x+1 for x in range(50)]

Lambdas: map(lambda y: y-2, [1,2,4,8,16,32])

At the moment the x in list comprehensions are exported to the rest of the
local scope, but that (mis)feature is officially going to be removed in
future versions of Python.


-- 
Steven.




More information about the Python-list mailing list