Lists implemented as integer-hashed Dictionaries?

Chris Rebert clp2 at rebertia.com
Fri Feb 6 22:44:09 EST 2009


> On Fri, Feb 6, 2009 at 10:25 PM, Chris Rebert <clp2 at rebertia.com> wrote:
>> On Fri, Feb 6, 2009 at 7:18 PM, er <erobererunc at gmail.com> wrote:
>> > Somebody much more intelligent than I said today that someone told him
>> > that
>> > Python lists are just dictionaries with lists hashed by integers.  Since
>> > he
>> > said that someone else told him this, I piped up and said that I thought
>> > that wasn't true.  I looked at the source code for lists in python, and
>> > I
>> > did not expressly remember seeing dictionaries.  Unfortunately I am not
>> > somewhere where I can easily look at the code right now (I'm logged into
>> > Windows!), and I might not realize exactly what I'm looking at anyways,
>> > but
>> > I'd like to extend an apology to the guy soon if I was wrong.  So, can
>> > anyone tell me if lists are really just dictionaries?  Thanks!
>>
>> They most certainly are not. This is Python, not Lua or PHP (where for
>> reasons I cannot fathom, they've seen fit to conflate dictionaries and
>> lists; although it does make slightly more sense in Lua's case)
>>
On Fri, Feb 6, 2009 at 7:32 PM, er <erobererunc at gmail.com> wrote:
> Thanks Chris.  Lua tables are one of my favorite linguistic traits, which
> was actually part of the discussion that brought up this nugget.
> Nevertheless, any details you care to provide about the details.  I'm going
> to dive into the source code in more depth tomorrow, just so I can get a
> better understanding anyway, but I'd love to hear some details, or see any
> links, if you have them.

Unfortunately, I don't know the details as I'm not a CPython dev. I
only indirectly know that arrays are used from having read so
previously in writings talking about the implementation. Also, Python
generally tries to make its basic datatypes speedy, and using
dictionaries to implement lists would be completely counter to that
goal, no matter how excellent the dictionary implementation is.

In all likelihood, someone who /is/ familiar with the implementation
will probably chime in with the actual details.

Cheers,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com



More information about the Python-list mailing list