[Python-ideas] Syntax for key-value iteration over mappings

MRAB python at mrabarnett.plus.com
Wed Jul 29 16:53:38 CEST 2015

On 2015-07-29 07:22, Pierre Quentel wrote:
> 2015-07-28 19:39 GMT+02:00 Petr Viktorin <encukou at gmail.com
> <mailto:encukou at gmail.com>>:
>     On Mon, Jul 27, 2015 at 6:23 AM, Ben Finney
>     <ben+python at benfinney.id.au <mailto:ben%2Bpython at benfinney.id.au>>
>     wrote:
>     On the other hand, parenthesizing it makes it look like an expression,
>     that is, something that can be part of a larger expression.
>     Key/value unpacking only works as a target of a "for".
> If the proposal was accepted for "for k:v in iterable" then I suppose
> that "if k:v in iterable" would also be valid, meaning that for a dict,
> there is a pair (k, v) such that _dict[k] = v, and for a list that there
> is an index k such that _list[k] = v.
"if k:v in iterable" is already valid syntax. It's "if k:", which is an 
if statement, followed by "v in iterable".

> for k:v in iterable:
>      assert k:v in iterable

More information about the Python-ideas mailing list