[Python-iterators] Re: PEP 234: Iterators
Guido van Rossum
guido at digicool.com
Tue May 1 08:44:37 EDT 2001
> > We could also add methods to dictionaries that return different kinds
> > of iterators
>
> Please do so.
>
> for k, v in dict.itemiter():
> ...
>
> is both more readable and more efficient than
>
> for k in dict:
> v = dict[k]
> ...
>
> The item-iterator can also be passed around whereas the other form
> cannot.
Excellent argument! I'll add it.
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-list
mailing list