Rant (was Re: x*x if x>10

Anders J. Munch 2007 at jmunch.dk
Sun Jul 27 14:35:19 EDT 2008


Gary Herron wrote:
>  >>> A = [1,2,3]
>  >>> B = [4,5,6]
>  >>> C = [7,8,9]
> 
>  >>> A+B+C
> [1, 2, 3, 4, 5, 6, 7, 8, 9]
> 
>  >>> sum([A,B,C], [])
> [1, 2, 3, 4, 5, 6, 7, 8, 9]

Careful now, this can be very slow.  sum uses __add__, not __iadd__, which gives 
this approach quadratic worst-case runtime.

- Anders



More information about the Python-list mailing list