[Tutor] Re: speeding code along [lists and dictionaries are fast]

Derrick 'dman' Hudson dman@dman.ddts.net
Mon Nov 18 19:19:02 2002


--k1lZvvs/B4yU6o8G
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Nov 18, 2002 at 08:56:32PM +0100, Magnus Lycka wrote:
| At 11:19 2002-11-18 -0700, Bob Gailer wrote:
| >I don't know how python manages lists internally
|=20
| AFAIK, it's basically an array of pointers.
[...]
| I haven't looked at the internals of lists, but they behave
| as if they would be implemented as I write here, as you can
| easily verify with some timing tests.

The core of a Python list is
    PyObject* []

It is (in C) an array of pointers to Python objects.  Hence it is very
fast for indexed lookups, but can be slower when appending many
objects to it.

| In reality it's probably a bit more complex.

The complexity comes in automatically growing when you append new
objectsts to the end of it and in deallocating objects when/as
appropriate.

-D

--=20
Consider what God has done:
    Who can straighten what He has made crooked?
        Ecclesiastes 7:13
=20
http://dman.ddts.net/~dman/

--k1lZvvs/B4yU6o8G
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj3ZhqAACgkQO8l8XBKTpRR35ACeP3uAjVZM9Js4YpBbRpBxuFIa
bzwAoJdNvpLJB/GecI121l5olTkYSSja
=1kVp
-----END PGP SIGNATURE-----

--k1lZvvs/B4yU6o8G--