Allowing negative `maxsplit` in `str.split`
Here's something that I would want now: An ability to give a negative `maxsplit` argument to `str.split`, to make it start splitting from the end of the string. For example, right now I wanted to be able to separate a module's name 'hello.world.meow' to ['hello.world', 'meow'] without knowing how many dots would be in the name. If I could give a `maxsplit` of -1 to achieve this, it would be nice. What do you think? Ram. (Please `cc` any replies to me if you can, thanks.)
On Sun, May 16, 2010 at 2:07 PM, cool-RR <cool-rr@cool-rr.com> wrote:
Here's something that I would want now: An ability to give a negative `maxsplit` argument to `str.split`, to make it start splitting from the end of the string. For example, right now I wanted to be able to separate a module's name 'hello.world.meow' to ['hello.world', 'meow'] without knowing how many dots would be in the name. If I could give a `maxsplit` of -1 to achieve this, it would be nice. What do you think?
What's wrong with 'hello.world.meow'.rsplit(maxsplit=1) ? Cheers, Chris -- http://blog.rebertia.com
On Sun, May 16, 2010 at 11:15 PM, Chris Rebert <pyideas@rebertia.com> wrote:
On Sun, May 16, 2010 at 2:07 PM, cool-RR <cool-rr@cool-rr.com> wrote:
Here's something that I would want now: An ability to give a negative `maxsplit` argument to `str.split`, to make it start splitting from the end of the string. For example, right now I wanted to be able to separate a module's name 'hello.world.meow' to ['hello.world', 'meow'] without knowing how many dots would be in the name. If I could give a `maxsplit` of -1 to achieve this, it would be nice. What do you think?
What's wrong with 'hello.world.meow'.rsplit(maxsplit=1) ?
Cheers, Chris -- http://blog.rebertia.com
What a noob I am, I didn't know that existed. Thanks Chris. Ram.
On Sun, May 16, 2010 at 14:18, cool-RR <cool-rr@cool-rr.com> wrote:
On Sun, May 16, 2010 at 11:15 PM, Chris Rebert <pyideas@rebertia.com> wrote:
On Sun, May 16, 2010 at 2:07 PM, cool-RR <cool-rr@cool-rr.com> wrote:
Here's something that I would want now: An ability to give a negative `maxsplit` argument to `str.split`, to make it start splitting from the end of the string. For example, right now I wanted to be able to separate a module's name 'hello.world.meow' to ['hello.world', 'meow'] without knowing how many dots would be in the name. If I could give a `maxsplit` of -1 to achieve this, it would be nice. What do you think?
What's wrong with 'hello.world.meow'.rsplit(maxsplit=1) ?
Cheers, Chris -- http://blog.rebertia.com
What a noob I am, I didn't know that existed. Thanks Chris.
`dir(str)` is your friend. -Brett
participants (3)
-
Brett Cannon
-
Chris Rebert
-
cool-RR