[Python-checkins] CVS: python/dist/src/Lib string.py,1.46,1.47
Gordon McMillan
gmcm at hypernet.com
Mon Feb 14 13:28:43 EST 2000
Adrian Eyre writes:
> I was refering to the connection with my original post about the join()
> method being added to the string object, when it more logically goes
> on a list/sequence...
>
> e.g.
>
> >>> s = "this is a test"
> >>> s.split()
> ['this', 'is', 'a', 'test']
>
> ...seems reasonable, but...
>
> >>> l = s.split()
> >>> " ".join(l)
> 'this is a test'
>
> ...doesn't. If it were on a list, you could do things like this:
>
> >>> s = "a:b:c"
> >>> s.split(":").join(", ")
> 'a, b, c'
And what should ['a',3,None,[Tim(1),Tim(2)]].join(';') return?
It would be most bizarre to have a method on list that only
worked for certain kinds of lists, (and guessing your intent is
the specialty of that other language).
Your needs are met by (", ").join("a:b:c".split(":")). Requiring
the arg to be a list-of-strings is restrictive, but not bizarre.
- Gordon
More information about the Python-list
mailing list