The inverse of .join

MRAB python at mrabarnett.plus.com
Thu Jun 17 15:44:41 EDT 2010


Neil Cerutti wrote:
> On 2010-06-17, Ian Kelly <ian.g.kelly at gmail.com> wrote:
>> On Thu, Jun 17, 2010 at 11:45 AM, Neil Cerutti
>> <neilc at norwich.edu> wrote:
>>> What's the best way to do the inverse operation of the .join
>>> function?
>> Use the str.split method?
> 
> split is perfect except for what happens with an empty string.
> 
I see what you mean.

This is consistent:

 >>> ','.join([''])
''
 >>> ''.split(',')
['']

but this isn't:

 >>> ','.join([])
''
 >>> ''.split(',')
['']

An empty string could be the result of .join(['']) or .join([]).

Should .split grow an addition keyword argument to specify the desired
behaviour? (Although it's simple enough to define your own function.)



More information about the Python-list mailing list