timing puzzle
Robin Becker
robin at NOSPAMreportlab.com
Fri Nov 16 14:55:28 EST 2007
Neil Cerutti wrote:
.......
see why.
>
> You are no longer making m copies of active_nodes.
my profiling indicated that the main problem was the removes.
>
........
>
> When you have to make many deletions from the middle of a
> sequence, you would normally choose a linked list. Python doesn't
> provide much support for linked lists, unfortunately.
>
> Instead, filter your list. It looks like you can't use filter
> directly, so just do it manually.
>
> for i in xrange(m):
> .......
> saved_nodes = []
> for A in active_nodes[:]:
> ......
> if not cond:
> saved_nodes.append(A)
>
> ......
> active_nodes = saved_nodes
> .....
>
I like this approach, better than mine.
--
Robin Becker
More information about the Python-list
mailing list