reduce to be removed?
DustanGroups at gmail.com
Sun Nov 12 00:48:05 CET 2006
Fredrik Lundh wrote:
> Dustan wrote:
> > It's always nice to know there are such good-natured people ready to
> > help on this group.
> any special reason why you keep pretending that some random wikipedia
> editor knows more about a future Python release than the people that
> develops Python ?
Be careful how you word that - this is the first time I've ever
referenced wikipedia in a question on this forum.
> > Anyway, I figured out a way to get the builtin
> > function 'sum' to work as I need:
> > sum([[1,2,3],[4,5,6],[7,8,9]], )
> sum() is designed for adding numbers, not sequences. abusing it
> for sequences leads to inefficient code, and extremely bad worst-
> case behaviour, since you end up copying the same data over and
> over and over again
Thanks for some quality feedback for a change. Why can't you do that
> -- the function even checks for strings for
> this very reason:
> >>> sum(["123", "456", "789"], "")
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> TypeError: sum() can't sum strings [use ''.join(seq) instead]
> (maybe it should check for other well-known containers as well?)
> if you care about writing robust code, why not just use a for-loop,
> and the list extend method?
Because I'm embedding this expression in a list comprehension (as I
stated in my original post), and last time I checked, it's not possible
to treat a for-loop as an expression (which is what a list
More information about the Python-list