Feature Proposal: Sequence .join method
Steven Bethard
steven.bethard at gmail.com
Thu Sep 29 22:37:31 EDT 2005
David Murmann wrote:
> Hi all!
>
> I could not find out whether this has been proposed before (there are
> too many discussion on join as a sequence method with different
> semantics). So, i propose a generalized .join method on all sequences
> with these semantics:
>
> def join(self, seq):
> T = type(self)
> result = T()
> if len(seq):
> result = T(seq[0])
> for item in seq[1:]:
> result = result + self + T(item)
> return result
>
> This would allow code like the following:
>
> [0].join([[5], [42, 5], [1, 2, 3], [23]])
I don't like the idea of having to put this on all sequences. If you
want this, I'd instead propose it as a function (perhaps builtin,
perhaps in some other module).
Also, this particular implementation is a bad idea. The repeated += to
result is likely to result in O(N**2) behavior.
STeVe
More information about the Python-list
mailing list