[Python-Dev] range objects in 3.x (original) (raw)
Ethan Furman ethan at stoneleaf.us
Tue Sep 27 20:20:25 CEST 2011
- Previous message: [Python-Dev] range objects in 3.x
- Next message: [Python-Dev] range objects in 3.x
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Steven D'Aprano wrote:
Ethan Furman wrote:
What about the idea of this signature?
frange([start], stop, step=None, count=None) Then when count is desired, it can be specified, and when step is sufficient, no change is necessary. A default of start=0 makes sense for integer range, because the most common use for range by far is for counting, and in Python we count 0, 1, 2, ... Similarly, we usually count every item, so a default step of 1 is useful. But for numeric work, neither of those defaults are useful. This proposed spread/frange/whatever function will be used for generating a sequence of equally spaced numbers, and not for counting. A starting value of 0.0 is generally no more special than any other starting value. There is no good reason to single out default start=0. Likewise a step-size of 1.0 is also arbitrary. It isn't useful to hammer the square peg of numeric ranges into the round hole of integer counts. We should not try to force this float range to use the same API as builtin range. (In hindsight, it is a shame that range is called "range" instead of "count". itertools got the name right.)
Good points. So how about:
some_name_here(start, stop, *, step=None, count=None)
? I personally would use the step value far more often than the count value.
Ethan
- Previous message: [Python-Dev] range objects in 3.x
- Next message: [Python-Dev] range objects in 3.x
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]