s.split() on multiple separators

Antoon Pardon apardon at forel.vub.ac.be
Tue Oct 2 13:03:23 CEST 2007

On 2007-10-02, Hrvoje Niksic <hniksic at xemacs.org> wrote:
> 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.

Sure it is a tradeoff and the python choice may in the end still turn
out the best. But that doesn't contradict that a number of
considerations were simply not mentioned in the article refered to.

>> 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.

Which I think is a good argument against using any convention and
having explict conditions for the boundaries to include or exclude

So instead of writing xrange(2,6) you have to write something like
xrange(2 <= x < 6) which explictly states 2 is included and 6 is
excluded. If someone wants both boundaries include he can write
xrange(2 <= x <= 5). 

A slice notation that would somehow indicate which boundaries are included
and which are excluded would be usefull IMO.

Antoon Pardon

More information about the Python-list mailing list