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

Chris Angelico rosuav at gmail.com
Tue Jul 28 03:43:11 CEST 2015


On Tue, Jul 28, 2015 at 11:29 AM, Andrew Barnert via Python-ideas
<python-ideas at python.org> wrote:
> On Jul 27, 2015, at 21:17, Steven D'Aprano <steve at pearwood.info> wrote:
>>
>> Keys and indices are not the same thing, and Python is not Lua.
>
> It may be worth doing a survey of other languages to see how they handle this.

Pike has two different forms of iteration:

foreach (some_object, value)

foreach (some_object; index; value)

The first form works on arrays and such - sequences. It's
fundamentally the same thing as Python's existing iteration. The
second form behaves the way I'm describing, and was the inspiration
for it :) But Pike's iterables are a lot more restricted than
Python's, so it's easier there.

ChrisA


More information about the Python-ideas mailing list