list problem
Duncan Booth
duncan at NOSPAMrcp.co.uk
Tue Sep 24 09:40:59 EDT 2002
Alex Martelli <aleax at aleax.it> wrote in
news:_FZj9.158106$pX1.5692316 at news2.tin.it:
> I _do_ think that reduce(operator.__add__, ...) is the only
> really frequent use of reduce, with such dominance that it might
> even be worth having as a built-in -- clearest and fastest. It
> might even specialcase _strings_ in particular, turning the op
> into a ''.join in this case... just musing...
The simplest thing could be to modify operator.add to accept any number of
arguments. Then you could use operator.add(*aList) to add up or concatenate
as appropriate all the elements of the list.
It still wouldn't be as fast as ''.join though unless you special cased it,
and it might be hard to special case it effectively: you would have to
check the types of all the objects in the list before deciding whether or
not to use join.
--
Duncan Booth duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
More information about the Python-list
mailing list