On 6/17/10 12:44 PM, MRAB wrote:
> Neil Cerutti wrote:
>> On 2010-06-17, Ian Kelly <ian.g.ke...@gmail.com> wrote:
>>> On Thu, Jun 17, 2010 at 11:45 AM, Neil Cerutti
>>> <ne...@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.)

Guido finds keyword-arguments-to-change-behavior to be unPythonic, IIRC.
It generally means 'make a new API'. But, the question is-- is it worth
the mental strain of a new API?

This is such an extreme edge case, having to do:

  if blah:
    result = blah.split(',')
  else:
    result = []

Is really not asking too much, I think.

-- 

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/

Attachment: signature.asc
Description: OpenPGP digital signature

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to