[Python-3000] Iterating over a dict (original) (raw)
Guido van Rossum guido at python.org
Sun Apr 2 18:29:13 CEST 2006
- Previous message: [Python-3000] Iterating over a dict
- Next message: [Python-3000] Iterating over a dict
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
-- --Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-3000] Iterating over a dict
- Next message: [Python-3000] Iterating over a dict
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]