PEP 234: Iterators
Russell E. Owen
owen at astrono.junkwashington.emu
Wed May 2 15:33:40 EDT 2001
In article <mailman.988683902.13127.python-list at python.org>,
Guido van Rossum <guido at digicool.com> wrote:
(Very nice proposal elided...)
>...We could also add methods to dictionaries that return
> different kinds of iterators, e.g.
>
> for key, value in dict.iteritems(): ...
>
> for value in dict.itervalues(): ...
>
> for key in dict.iterkeys(): ...
Yes! A suggested enhancement: each of these functions takes an optional
argument "sorted" which defaults to false (e.g. 0 or None) but could be
true (e.g. 1). Setting it true iterates over the dictionary in
keyword-sorted order.
I find I often want to iterate over a dictionary in keyword-sorted
order, and it's rather ugly to do right now (partly because "sort"
doesn't return the sorted list). This would neatly handle the situation.
-- Russell
More information about the Python-list
mailing list