opposite of dict.items()

Chad Netzer cnetzer at sonic.net
Fri Aug 29 13:34:00 EDT 2003


On Fri, 2003-08-29 at 04:53, Peter Otten wrote:

> >>> dict(izip(irange(3), "abc"))
> {0: 'a', 1: 'b', 2: 'c'}
> 
> If I could use the above in Py2.4, it would be even nicer, namely:
> 
> - convert itertools to builtins

The push is to have LESS builtins.  You can always import them in to the
current namespace:

from itertools import izip

> - add irange(), perhaps as an alias for xrange() like file/open

I suggested an irange to Raymond, and even coded one up, a while ago. 
He sees it as bloat, and rightfully so, since there is a push to allow
optimizations of range that would achieve the same effect.  (ie. rather
than remembering when to use range(), xrange(), or irange(), we could
just always use range() and the language would do lazy evaluation
whenever possible.)  Unless that avenue turns out to be a complete dead
end, don't expect an irange().

BTW.  In the example you used, you COULD use xrange().  The only problem
is that range has been extended, in 2.3, to accept longs, and xrange()
only works with ints, and Guido wants it that way (he doesn't want to
extend xrange()'s features, since it is a pain.)  irange(), if it ever
appears, would presumably be fully range() compatible.

-- 
Chad Netzer






More information about the Python-list mailing list