frange=lambda start, stop=0.0, step=1.0, include_stop=False:
(
(min if step > 0 else max)((start, stop)) + index*step
for index in xrange(int(abs(start - stop) / abs(step) + 1))
if index*step < (abs(start-stop) + (step if include_stop else 0))
)
Like the
xrange()
and range()
functions, the generated sequence does not include the stop-value. However, since inclusive ranges are quite useful with floats, the default behaviour can be overridden by setting the include_stop
argument to True
. In this case the stop
-value is included in the range if it is a multiple of step
s from start
.
No comments:
Post a Comment