A proposal idea for string.split with negative maxsplit

A

Antoon Pardon

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.
["st1" , "st2" , "st3:st4:st5"]


This behaviour would remain but additionally we would have the
following.
["st1:st2:st3" , "st4" , "st5"]


What do people think here?
 
F

Fredrik Lundh

Antoon said:
This behaviour would remain but additionally we would have the
following.
["st1:st2:st3" , "st4" , "st5"]

What do people think here?
['st1:st2:st3', 'st4', 'st5']

</F>
 
A

Antoon Pardon

Op 2005-01-28 said:
Antoon said:
This behaviour would remain but additionally we would have the
following.
"st1:st2:st3:st4:st5".split(':',-2)
["st1:st2:st3" , "st4" , "st5"]

What do people think here?
"st1:st2:st3:st4:st5".rsplit(':', 2)
['st1:st2:st3', 'st4', 'st5']

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,158
Latest member
Vinay_Kumar Nevatia
Top