[Tutor] creating a range above & below a given number
Gonzalo Garcia-Perate
gonzillaaa at gmail.com
Sat Jun 6 21:31:04 CEST 2009
Hello tutor, What's the simplest way of creating a list with a range
of numbers above and below a given number?
see the function below:
def within_range( self, number, median, threshold=5 ):
# build a list of (threshold) numbers above and below median
range_list = range( median - threshold, median )
range_list.extend( range( median, median + ( threshold + 1 ) ) )
if __debug__: print "number %s, median %s, within range %s,
list %s, list length %s" % ( number, median, number in range_list,
range_list, len( range_list ) )
if number not in range_list: return False
return True
this works fine, but is there a simpler way of doing it? a one liner? :)
Thanks,
More information about the Tutor
mailing list