osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

join and split with empty delimiter


On 2019-07-18 20:52, Ben Bacarisse wrote:
> Danilo Coccia <daniloco at acm.org> writes:
> 
>> Il 18/07/2019 12:27, Ben Bacarisse ha scritto:
[snip]
>>> Of course str.split('') could be defined to work the way you expect, but
>>> it's possible that the error is there to prompt the programmer to be
>>> more explicit.
>>
>> It is even more ambiguous if you consider that any string starts with an
>> infinite number of empty strings, followed by a character, followed by
>> an infinite number of empty strings, followed by ...
>> The result wouldn't fit on screen, or in memory for that!
> 
> Right, but that can be finessed by saying that two delimiters can't
> overlap, which is the usual rule.  A reasonable interpretation of "not
> overlapping" might well exclude having more the one delimiter in the
> same place.
> 
The delimiters wouldn't be overlapping, they'd be adjacent, but it does 
seem reasonable not to split on an empty delimiter more than once at a 
certain position. That's what a regex split (usually) does (in the re 
module since Python 3.7, and in other regex implementations).