Speed

Peter Schneider-Kamp petersc at stud.ntnu.no
Sun May 14 13:55:26 CEST 2000


Janos Blazi wrote:
> 
>     r = [cnt,last] + r
      ^^^^^^^^^^^^^^^^^^
Hei Janos!

You append at the beginning of the list.
That's a bad idea as lists are implemented as
resizable arrays in Python.

If you write
r.extend([last,cnt])
instead the code needs less than 3 seconds
on my system (did not test the C version).

Of course the rest of the code has to be
changed to reflect this.

> Is my Python code stupid? Can I improve it?

Nein, einfach nur ungeschickt in Hinsicht auf
Pythons interne Datenstrukturen. Eigentlich
sollte man sich mit sowas nicht beschäftigen
müssen. Theoretisch ...

Ha det bra
Peter
--
Peter Schneider-Kamp          ++47-7388-7331
Herman Krags veg 51-11        mailto:peter at schneider-kamp.de
N-7050 Trondheim              http://schneider-kamp.de




More information about the Python-list mailing list