Lists implemented as integer-hashed Dictionaries?
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Sun Feb 8 13:48:24 EST 2009
En Sat, 07 Feb 2009 01:18:37 -0200, er <erobererunc at gmail.com> escribió:
> Somebody much more intelligent than I said today that someone told him
> that Python lists are just dictionaries with lists hashed by integers.
In addition to all other responses you received, I'd add that lists and
dictionaries share the same syntax a[x] and the same magic methods in
Python code (__getitem__, __setitem__, __delitem__). But the similarity
stops here. The CPython implementation has two different sets of methods,
one for sequences and other for mappings, so when you override e.g.
__getitem__ in Python code it replaces either sq_item or mp_subscript
depending on which one is defined.
Other implementations might choose to do different, but at least on
standard PC hardware I can't imagine how to efficiently implement lists as
dictionaries...
--
Gabriel Genellina
More information about the Python-list
mailing list