Alex Martelli aleax at
Thu Jun 19 22:26:49 CEST 2003

Paul Rubin wrote:

> Alex Martelli <aleax at> writes:
>> No, if sum accepted a sequence of strings it WOULD
>> have to delegate to ''.join in that case -- and I just couldn't
>> find an elegant and totally general way to do that.
> Why can't it just check if all the values are strings, and delegate if
> they are?

That would require _saving_ all the values (potentially taking up
over twice as much memory) in order to allow the argument to be any
iterable (including a non-restartable one).  I'm not saying it's
_impossible_: I'm saying Guido Pronounced against it (or other
similar tricks) as being worth the bother.  There are IMHO-better
tricks: I _could_ have checked just the _first_ item -- if that's
an instance of basestring call ''.join with a custom iterator that
returns that one checked-item then delegates the rest to the stepped-
by-one iterator on the argument -- ''.join will handle the error
diagnostics if any of the other items isn't an instance of basestring.
It's still complication, not simplicity, elegance and generality.


More information about the Python-list mailing list