s.split() on multiple separators

Hrvoje Niksic hniksic at xemacs.org
Tue Oct 2 04:14:45 EDT 2007


Antoon Pardon <apardon at forel.vub.ac.be> writes:

> It may be convincing if you only consider natural numbers in
> ascending order. Suppose you have the sequence a .. b and you want
> the reverse.  If you work with included bounds the reverse is just b
> .. a. If you use the python convention, things become more
> complicated.

It's a tradeoff.  The convention used by Python (and Lisp, Java and
others) is more convenient for other things.  Length of the sequence
x[a:b] is simply b-a.  Empty sequence is denoted simply with x[a:a],
where you would need to use the weird x[a:a-1] with inclusive bounds.
Subsequences such as x[a:b] and x[b:c] merge smoothly into x[a:c],
making it natural to iterate over subsequences without visiting an
element twice.

> Another problem is if you are working with floats. Suppose you have
> a set of floats. Now you want the subset of numbers that are between
> a and b included.  If you want to follow the convention that means
> you have to find the smallest float that is bigger than b, not a
> trivial task.

The exact same argument can be used against the other convention: if
you are working with inclusive bounds, and you need to represent the
subset [a, b), you need to find the largest float that is smaller than
b.



More information about the Python-list mailing list