[Python-Dev] Re: PEP 279 revisited
Guido van Rossum
Wed, 24 Apr 2002 08:47:25 -0400
> If you consider lists to be a special dictionary
> with implicit keys we can define 'items' to
> generate (key,value) pairs for a collection so that
> for key,value in items(collection):
> holds no matter if collection is a list or a dictionary,
This has been proposed and rejected before. We've made the decision
that "iter(dict)" iterates over the keys while "iter(list)" iterates
over the values, and anything that tries to unify the two types
(really categories of types: sequences and mappings) is bound to fail.
> btw, i usually don't need an extra numbering for my dictionaries.
> If really in need i would write
> list = dict.items()
> for index,item in items(list): ...
> using the above semantics.
That's another argument why what this function (whatever it's called)
does on dicts is irrelevant: you wouldn't want to use it on a dict
anyway. It's something for sequences and iterators.
--Guido van Rossum (home page: http://www.python.org/~guido/)