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

Lennart Regebro regebro at gmail.com
Mon Jul 27 13:42:16 CEST 2015

On Mon, Jul 27, 2015 at 4:12 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> It's one more special case syntax for beginners to learn. And it really
> is a special case: there's nothing about "for k:v in iterable" that
> tells you that iterable must have an items() method. You have to
> memorise that fact.

This I think is a strong argument.

What error would you get when it's the wrong type? An attribute error
on .items(), or a special SyntaxError "This syntax can only be used on
Both are quite incomprehensible unless you know exactly what is going
on and that this is a shortcut for "fox x,y in foo.items():"

More information about the Python-ideas mailing list