Stupid string.split question

Andrew Dalke adalke at mindspring.com
Wed Aug 6 20:56:11 EDT 2003


Peter Hansen:
> It's only a token kind of symmetry, without much real value.  After
> all, why shouldn't this be symmetrical, too, then? :
>
>   ''.join(['abc', 'def', 'g', 'h']) --> 'abcdefgh'
>
>   'abcdefgh'.split('') --> ['abc', 'def', 'g', 'h']

That's a different symmetry than what Brian is arguing.
He doesn't expect

   "a".join(["abc", "def", "cab"]) --> "abcadefacab"

   "abcadefacab".split() --> ["abc", "def", "cab"]

Instead, he is bothered because the following doesn't work
when sep == ""

def split_join(s, sep):
  return s == sep.join(s.split(sep)):

                    Andrew
                    dalke at dalkescientific.com






More information about the Python-list mailing list