s.split() on multiple separators

Lawrence D'Oliveiro ldo at geek-central.gen.new_zealand
Thu Oct 4 03:34:49 EDT 2007


In message <slrnfg3tl0.fm5.apardon at rcpc42.vub.ac.be>, Antoon Pardon wrote:

> On 2007-10-01, Gabriel Genellina <gagsl-py2 at yahoo.com.ar> wrote:
>
>> En Sun, 30 Sep 2007 16:16:30 -0300, <mrkafk at gmail.com> escribi?:
>>
>>>> From my POV, if I want sequence from here to there, it should include
>>> both here and there.
>>>
>>> I do understand the consequences of making high bound exclusive, which
>>> is more elegant code: xrange(len(c)). But it does seem a bit
>>> illogical...
>>
>> See this note from E.W.Dijkstra in 1982 where he says that the Python
>> convention is the best choice.
>> http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html
> 
> 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.

Nothing complicated about it:

    >>> a = 1
    >>> b = 5
    >>> range(a, b)
    [1, 2, 3, 4]
    >>> range(b - 1, a - 1, -1)
    [4, 3, 2, 1]

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

Due to precision limitations, the set will probably not be what you think it
is, anyway.



More information about the Python-list mailing list