range or xrange disallowed for big numbers

GerritM gmuller at worldonline.nl
Sat Oct 5 12:47:07 EDT 2002


"Alex Martelli" <aleax at aleax.it> schreef in bericht
news:d4zn9.7557$Fz.214524 at news1.tin.it...
> Chad Netzer wrote:
<... in summary how to make a range for very large integer?...>
<...snip...>
>
> Maybe rather than fixing either
> type a new, perhaps Python-coded built-in generator could be added:
>
> def genrange(start, stop=None, step=1):
>     if step == 0:
>         raise ValueError, "step can't be 0"
>     if stop is None:
>         start, stop = 0, start
>     if step > 0:
>         while start < stop:
>             yield start
>             start += step
>     else:
>         while start > stop:
>             yield start
>             start += step
>
>
> Alex
>
Wonderful snippet, should certainly be added to the cookbook!

thanks, Gerrit





More information about the Python-list mailing list