[Python-Dev] "funny".split("")

Andrew Koenig ark@research.att.com
12 Mar 2002 13:43:17 -0500


>> Why this?
>> I would expect

>> ['f','u','n','n','y']

Brian> Why wouldn't you expect this: 
Brian> ['', 'f', 'u', 'n', 'n', 'y', '']

For the same reason I wouldn't expect this:

['', '', 'f', 'u', 'n', 'n', 'y', '', '']

whatever that reason might be.  That is:  You give me a reason why
I should expect ['', 'f', 'u', 'n', 'n', 'y', ''] instead of
['f','u','n','n','y'] and I'll warrant that the same reason,
whatver it might happen to be, would argue also for
['', '', 'f', 'u', 'n', 'n', 'y', '', '']

If you're going to allow a null separator at all, then there has to be
a rule to choose one of the infinite number of possible return values.

One plausible rule, which would have the advantage of working the
same for empty and nonempty separators, is that no element of
the result can be equal to the separator.

-- 
Andrew Koenig, ark@research.att.com, http://www.research.att.com/info/ark