PEP 260: simplify xrange()
D-Man
dsh8290 at rit.edu
Tue Jun 26 19:18:33 EDT 2001
On Tue, Jun 26, 2001 at 11:51:12PM +0400, Roman Suzi wrote:
|
| And also I think "x in xrange(...)" and
| "x not in xrange(...)" should not be dropped,
| because it is very near to
|
| for x in xrange(...)
|
| and has interesting use as in:
|
| if n in xrange(1, 101, 2): # odd number from [1, 100]
| ...
Cute, but how about (for this particular example)
if 1 <= n <= 101 and n % 2 == 1 :
...
or
def odd_in_range( n , lower , upper :
return 1 <= n <= 101 and n % 2 == 1
if odd_in_range( n , 1 , 101 )
In fact, prior to the PEP, I didn't know that xrange() could be used
anywhere except a for loop. I hadn't tried, nor had I read the docs
;-).
-D
More information about the Python-list
mailing list