sum for sequences?
Duncan Booth
duncan.booth at invalid.invalid
Wed Mar 24 12:20:17 EDT 2010
kj <no.email at please.post> wrote:
> Is there a sequence-oriented equivalent to the sum built-in? E.g.:
>
> seq_sum(((1, 2), (5, 6))) --> (1, 2) + (5, 6) --> (1, 2, 5, 6)
>
> ?
>
Apart from the suggestions for Google for general list flattening, for this
specific example you could just use the 'sum' built-in:
>>> sum(((1, 2), (5, 6)), ())
(1, 2, 5, 6)
Just give it an empty tuple as the starting value.
More information about the Python-list
mailing list