This was discussed in the String methods... finally thread in the Python-Dev achive, and was accepted by Guido. This thread began in Jun 1999, and str.join
was included in Python 1.6 which was released in Sep 2000 (and supported Unicode). Python 2.0 (supported str
methods including join
) was released in Oct 2000.
str.join(seq)
seq.join(str)
seq.reduce(str)
join
as a built-in functionlist
s, tuple
s, but all sequences/iterables.seq.reduce(str)
is difficult for new-comers.seq.join(str)
introduces unexpected dependency from sequences to str/unicode.join()
as a built-in function would support only specific data types. So using a built in namespace is not good. If join()
supports many datatypes, creating optimized implementation would be difficult, if implemented using the __add__
method then it's O(n²).sep
) should not be omitted. Explicit is better than implicit.There are no other reasons offered in this thread.
Here are some additional thoughts (my own, and my friend's):
Guido's decision is recorded in a historical mail, deciding on str.join(seq)
:
Funny, but it does seem right! Barry, go for it...
--Guido van Rossum