Recall that for every character in a string, there are empty strings before and after all characters.
['', '', '', '', '', '', '', '']
Note that when we split on
a, which is seven characters long, the result is eight empty strings.
There must be some reason that we get only one empty string when splitting on
['a', '', 'le']
and no empty strings when splitting on
How the algorithm sorts this out is a little beyond me though I suspect that it has something to do with the inverse method,
join. Any split string should be restorable using
str.join() with the same separator string used in the
>>> 'a'.join(['', '', '', '', '', '', '', ''])
>>> 'p'.join(['a', '', 'le'])
>>> 'pp'.join(['a', 'le'])
As to that algorithm, it will take some research to find and explore the workings behind
join but that would be chasing down a rabbit hole, at this point in time. Keep this question in mind for extra study once you are have more of the practical and rudimentary language skills under one’s belt.
Note the behavior of
join when the separator is an empty string…
>>> ''.join(['', '', '', '', '', '', '', ''])
>>> ''.join(['a', '', 'le'])
>>> ''.join(['a', 'le'])