[Python-3000] Iterating over a dict

Georg Brandl g.brandl at gmx.net
Sun Apr 2 21:01:04 CEST 2006

Guido van Rossum wrote:
> On 4/1/06, Thomas Lotze <thomas.lotze at gmx.net> wrote:
>> Hi,
>> I wonder what's the reason for iterating over a dict by keys:
>> >>> for x in {1:"a", 2:"b"}:
>> ...     print x
>> ...
>> 1
>> 2
>> I find it much more intuitive for the values, "a" and "b", to be accessed.
>> This is particularly confusing as iterating over tuples, lists and sets in
>> the same way does access the values. (It feels like iterating over a list
>> l actually iterates over the index values, range(len(l)).) In fact,
>> iterating over any container should access the contained values.
>> The reason I ask this on the python-3000 list is that I wonder whether the
>> iterating behaviour of dicts might be changed in Python 3k, so that in the
>> above code, foo() would be applied to the dict's values.
> Just to confirm what's already been said, this was considered very
> carefully and won't change.

A quick idea of mine: Wouldn't it be useful to maintain a list of what will
not change, collected in the discussions here? That way, people eager to suggest
braces and whatnot can be referred to it.

(I'd be volunteering to maintain such a list/PEP/whatever).


More information about the Python-3000 mailing list