[Python-Dev] join()
Ka-Ping Yee
ping at lfw.org
Sat Jun 12 10:12:38 CEST 1999
On Fri, 11 Jun 1999, Skip Montanaro wrote:
>
> BAW> The only reason for making it a builtin would be to avoid pulling
> BAW> in all of string just to get join.
>
> I still don't understand the motivation for making it a builtin instead of a
> method of the types it operates on. Making it a builtin seems very
> un-object-oriented to me.
Builtin-hood makes it possible for one method to apply to
many types (or a heterogeneous list of things).
I think i'd support the
def join(list, sep=None):
if sep is None:
result = list[0]
for item in list[1:]:
result = result + item
else:
result = list[0]
for item in list[1:]:
result = result + sep + item
idea, basically a reduce(operator.add...) with an optional
separator -- *except* my main issue would be to make sure that
the actual implementation optimizes the case of joining a
list of strings. string.join() currently seems like the last
refuge for those wanting to avoid O(n^2) time when assembling
many small pieces in string buffers, and i don't want it to
see it go away.
!ping
More information about the Python-Dev
mailing list