A proposal idea for string.split with negative maxsplit

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Antoon Pardon

    A proposal idea for string.split with negative maxsplit


    I was wondering what people whould think about a change of behaviour
    in the split method fo strings. The idea would be that if maxsplit
    was negative then abs(maxsplit) splits would be done, but splitting
    would start from the right instead of the left.

    Now we have.
    [color=blue][color=green][color=darkred]
    >>> "st1:st2:st3:st 4:st5".split(': ',2)[/color][/color][/color]
    ["st1" , "st2" , "st3:st4:st 5"]


    This behaviour would remain but additionally we would have the
    following.
    [color=blue][color=green][color=darkred]
    >>> "st1:st2:st3:st 4:st5".split(': ',-2)[/color][/color][/color]
    ["st1:st2:st 3" , "st4" , "st5"]


    What do people think here?

    --
    Antoon Pardon
  • Fredrik Lundh

    #2
    Re: A proposal idea for string.split with negative maxsplit

    Antoon Pardon wrote:
    [color=blue]
    > This behaviour would remain but additionally we would have the
    > following.
    >[color=green][color=darkred]
    >>>> "st1:st2:st3:st 4:st5".split(': ',-2)[/color][/color]
    > ["st1:st2:st 3" , "st4" , "st5"]
    >
    > What do people think here?[/color]
    [color=blue][color=green][color=darkred]
    >>> "st1:st2:st3:st 4:st5".rsplit(' :', 2)[/color][/color][/color]
    ['st1:st2:st3', 'st4', 'st5']

    </F>



    Comment

    • Antoon Pardon

      #3
      Re: A proposal idea for string.split with negative maxsplit

      Op 2005-01-28, Fredrik Lundh schreef <fredrik@python ware.com>:[color=blue]
      > Antoon Pardon wrote:
      >[color=green]
      >> This behaviour would remain but additionally we would have the
      >> following.
      >>[color=darkred]
      >>>>> "st1:st2:st3:st 4:st5".split(': ',-2)[/color]
      >> ["st1:st2:st 3" , "st4" , "st5"]
      >>
      >> What do people think here?[/color]
      >[color=green][color=darkred]
      >>>> "st1:st2:st3:st 4:st5".rsplit(' :', 2)[/color][/color]
      > ['st1:st2:st3', 'st4', 'st5'][/color]

      Damn, I was looking in the wrong version of the docs when I was
      looking for this. Sorry about that.

      --
      Antoon Pardon

      Comment

      Working...