[Python-3000] Ordered mapping type for Python 3000?
jcarlson at uci.edu
Tue Mar 27 20:45:28 CEST 2007
Frank Benkstein <frank-python at benkstein.net> wrote:
> One thing that has come up quite often IIRC is the request for an
> ordered mapping type. It would like to propose to add such a type to
> Python 3000 and make it immutable, to prevent all kind of problems that
> would occur otherwise. Other than that it should behave just
> the same as dictionaries for all non-modifying operations.
In the course of my Python programming, while I have thought it would be
convenient to have a mutable sorted mapping (implemented via key, value
binary tree), and a mutable indexed sequence (implemented via
order-statistic binary tree, for O(logn) insertions and deletions
anywhere), about the only time where an ordered mapping would have made
sense, whose order depends on definition ordering, has been like ...
a = ...
b = ...
As is the case when creating database schemas via SQLAlchemy, etc.
There is a PEP (that is more or less accepted) for offering this
*particular* use-case in py3k.
> Furthermore it would be nice to have this new type as the default type
> for **-style keyword parameters. First it would make creating the
> instances of this new type a lot easier and second it would remove the
> asymmetry in having a immutable *args and a mutable **kwds.
I believe the reason for immutable *args is one of optimization. For
quite a while it was faster to create a tuple than a list, and even
things like tuple(GENERATOR_EXPRESSION) were faster than
list(GENERATOR_EXPRESSION) . I don't believe that the same argument
applies to an immutable ordered mapping, and I've heard very few
complaints about immutable vs mutable args and kwargs.
More information about the Python-3000