Arithmetic sequences in Python
Paul Rubin
http
Mon Jan 16 05:58:39 EST 2006
Steven D'Aprano <steve at REMOVETHIScyber.com.au> writes:
> For finite sequences, your proposal adds nothing new to existing
> solutions like range and xrange.
Oh come on, [5,4,..0] is much easier to read than range(5,-1,-1).
> The only added feature this proposal
> introduces is infinite iterators, and they aren't particularly hard to
> make:
>
> def arithmetic_sequence(start, step=1):
> yield start
> while 1:
> start += step
> yield start
Well, that would be itertools.count(start, step) but in general a simple
expression is nicer than 5 lines of code.
> If your proposal included support for ranges of characters, I'd be more
> interested.
There's something to be said for that. Should ['a'..'z'] be a list or
a string?
More information about the Python-list
mailing list