RE: PEP 260: simplify xrange()
Here's another sweet and short PEP. What do folks think? Is xrange()'s complexity really worth having?
--Guido van Rossum (home page: http://www.python.org/~guido/)
PEP: 260 Title: Simplify xrange() Version: $Revision: 1.1 $ Author: guido@python.org (Guido van Rossum) Status: Draft Type: Standards Track Python-Version: 2.2 Created: 26-Jun-2001 Post-History: 26-Jun-2001
Abstract
This PEP proposes to strip the xrange() object from some rarely used behavior like x[i:j] and x*n.
Problem
The xrange() function has one idiomatic use:
for i in xrange(...): ...
If this is to be done, I would also propose that xrange() and range() be changed to allow passing in a straight-out sequence such as in the following code in order to get rid of the need for range(len(seq)): import __builtin__ def range (start, stop=None, step=1, range=range): """""" start2 = start stop2 = stop if stop is None: stop2 = start start2 = 0 try: return range(start2, stop2, step) except TypeError: assert stop is None return range(len(start)) def xrange (start, stop=None, step=1, xrange=xrange): """""" start2 = start stop2 = stop if stop is None: stop2 = start start2 = 0 try: return xrange(start2, stop2, step) except TypeError: assert stop is None return xrange(len(start)) a = [5, 'a', 'Hello, world!'] b = range(a) c = xrange(4, 6) d = xrange(b) e = range(c) print a print b print c print d print e print range(d, 2) Tim Delaney
On 27 June 2001, Delaney, Timothy said:
If this is to be done, I would also propose that xrange() and range() be changed to allow passing in a straight-out sequence such as in the following code in order to get rid of the need for range(len(seq)):
I'm +1 on the face of it without stopping to consider any implications. ;-) Some bits of syntactic sugar as just too good to pass up. range(len(sequence)) is syntactic cod-liver oil. Greg -- Greg Ward - programmer-at-big gward@python.net http://starship.python.net/~gward/ Blood is thicker than water, and much tastier.
participants (2)
-
Delaney, Timothy
-
Greg Ward