[Python-ideas] [...].join(sep)

Bruce Leban bruce at leapyear.org
Wed May 23 17:29:28 CEST 2012


On Wed, May 23, 2012 at 7:50 AM, Boris Borcic <bborcic at gmail.com> wrote:

> Kind of beside the point, which is that the desire to repair the
> inconsistency between split and join has a better prospect at the split
> side of things than at the join side of things. The problems at the split
> side of things are comparatively minor.
>


The inconsistency that bugs me is the difference in split behavior between
languages. Switching between languages means I have to constantly double
check this. What is consistent is that you call string.split(separator)
rather than separator.split(string) so changing that doesn't seem at all
beneficial.

Python split has an optional *maxsplit* parameter:

If maxsplit is given, at most maxsplit splits are done (thus, the list will
have *at most maxsplit+1* elements).

The remainder of the string after the last matched separator is included in
the last part.


Java split has an optional integer *limit* parameter:

... the pattern will be applied at most limit - 1 times, the array's length
will be *no greater than limit* ...

The remainder of the string after the last matched separator is included in
the last part.


C# split has an optional *count* parameter:

The maximum number of substrings to return.
The remainder of the string after the last matched separator is included in
the last part.


Ruby split has an optional limit parameter:

If limit is a positive number, *at most that number of fields* will be
returned.
The remainder of the string after the last matched separator is included in
the last part.


Javascript has an optional limit parameter:

It returns *at most limit* parts.

The remainder of the string after the last matched separator is *discarded*.


And I'm not mentioning the differences in how the separator parameter is
interpreted. :-)

--- Bruce
Follow me: http://www.twitter.com/Vroo http://www.vroospeak.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20120523/990c7714/attachment.html>


More information about the Python-ideas mailing list