Algorithm help per favore

Bengt Richter bokr at oz.net
Wed Jun 18 19:21:07 EDT 2003


On Wed, 18 Jun 2003 15:28:35 -0700 (PDT), Curly Joe <woooee at yahoo.com> wrote:

>Correct me if I'm wrong, but doesn't the compiler
>break all of these solutions down into approximately
>the same thing? The compiler has to physically step
>through the list one by one no matter how you phrase
>the code, so there would be no gain in speed.  There
>might be a small speedup for larger lists if you
>placed the previous element in a variable and compare
>the variable to this element, because then the
>compiler would only have to access one element instead
>of two elements in each pass.  But aside from that it
>seems that it is all window dressing IMHO.  I'm no
>expert on lists.  Good question though.
>
There's a lot of difference in what happens. E.g., if you zip
an offset copy to make a list of tuples, you've duplicated the
first list and made an equally long list of 2-tuples. And then
you start constructing the result list.

Destructive modification of the original list is going to take
very much less space for large lists, and likely be faster (depending
on how you do it ;-)

You can compare the code generated by disassembling with the dis module.

Regards,
Bengt Richter




More information about the Python-list mailing list