> What object is the scope of a comprehension (in Py 3; in py 2 they don't have their own scope) a dict attached to? The generator object that gets created behind the scenes. > And, if you can answer that why could…
In Python 3, list comprehensions use generators behind the scenes.
Not introducing a new scope with a match is unfortunate, but it's also consistent with how every other language feature interacts with scoping. > (As well as a method to “pin” variables from the containing scope to use…
The explanation is that (in Python 3) list comprehensions are really just syntactic sugar for generator expressions. In Python, "scope" is really a synonym for "dictionary attached to some object", so generators can…
If you really need to compare against a variable, use an "if". The primary benefit of pattern-matching is destructuring. EDIT: It looks like you actually can match against constants with this PEP, as long as you access…
That's just an inevitable consequence of the fact that, in Python, "scope" is synonymous with "dictionary attached to some object." This is already how for-loops work.
This is how pattern matching works in any language (except for some niche languages that allow nonlinear patterns, like Curry). Many of the comments here reveal a bizarre parochialism.
That's essentially the leading theory. They're called WIMPs.
> What object is the scope of a comprehension (in Py 3; in py 2 they don't have their own scope) a dict attached to? The generator object that gets created behind the scenes. > And, if you can answer that why could…
In Python 3, list comprehensions use generators behind the scenes.
Not introducing a new scope with a match is unfortunate, but it's also consistent with how every other language feature interacts with scoping. > (As well as a method to “pin” variables from the containing scope to use…
The explanation is that (in Python 3) list comprehensions are really just syntactic sugar for generator expressions. In Python, "scope" is really a synonym for "dictionary attached to some object", so generators can…
If you really need to compare against a variable, use an "if". The primary benefit of pattern-matching is destructuring. EDIT: It looks like you actually can match against constants with this PEP, as long as you access…
That's just an inevitable consequence of the fact that, in Python, "scope" is synonymous with "dictionary attached to some object." This is already how for-loops work.
This is how pattern matching works in any language (except for some niche languages that allow nonlinear patterns, like Curry). Many of the comments here reveal a bizarre parochialism.
That's essentially the leading theory. They're called WIMPs.