sum for sequences?

Steve Howell showell30 at yahoo.com
Sun Mar 28 19:34:13 CEST 2010


On Mar 28, 10:21 am, Steve Howell <showel... at yahoo.com> wrote:
>     import timeit
>     M = 10
>     N = 8000
>
>     def in_place(
>         start = [],
>         sublists = ([[None] * M]) * N
>         ):
>         # only macro-optimized
>         i = 0
>         for sublist in sublists:
>             if i == 0:
>                accum = start + sublist
>                i += 1
>             else:
>                 accum.extend(sublist)

FYI I later obtained similar results with the more general:
                  accum += sublist

>         if i == 0:
>             return 'whatever' # semantics here?
>         return accum
>
>     def with_intermediates(
>         start = [],
>         sublists = ([[None] * M]) * N
>         ):
>         accum = start
>         for sublist in sublists:
>             accum = accum + sublist
>         return accum
>



More information about the Python-list mailing list