469,307 Members | 1,820 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,307 developers. It's quick & easy.

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.
"st1:st2:st3:st4:st5".split(':',2) ["st1" , "st2" , "st3:st4:st5"]
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?

--
Antoon Pardon
Jul 18 '05 #1
2 1768
Antoon Pardon wrote:
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']

</F>

Jul 18 '05 #2
Op 2005-01-28, Fredrik Lundh schreef <fr*****@pythonware.com>:
Antoon Pardon wrote:
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.

--
Antoon Pardon
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Carlos Ribeiro | last post: by
108 posts views Thread by Bryan Olson | last post: by
33 posts views Thread by C# Learner | last post: by
4 posts views Thread by Michele Petrazzo | last post: by
25 posts views Thread by John Salerno | last post: by
4 posts views Thread by Steven D'Aprano | last post: by
7 posts views Thread by Matt | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.