[Python-checkins] r64306 - peps/trunk/pep-0372.txt
Nick Coghlan
ncoghlan at gmail.com
Mon Jun 16 14:55:39 CEST 2008
georg.brandl wrote:
> Author: georg.brandl
> Date: Mon Jun 16 12:15:48 2008
> New Revision: 64306
>
> Log:
> Updates and fixes from Armin.
>
>
> Modified:
> peps/trunk/pep-0372.txt
>
> Modified: peps/trunk/pep-0372.txt
> ==============================================================================
> --- peps/trunk/pep-0372.txt (original)
> +++ peps/trunk/pep-0372.txt Mon Jun 16 12:15:48 2008
> @@ -31,8 +31,8 @@
> Some dynamic programming languages like PHP and Ruby 1.9 guarantee a
> certain order on iteration. In those languages, and existing Python
> ordered-dict implementations, the ordering of items is defined by the
> -time of insertion of the key. New keys are appended at the end, keys
> -that are overwritten and not moved.
> +time of insertion of the key. New keys are appended at the end, but
> +keys that are overwritten are not moved to the end.
>
> The following example shows the behavior for simple assignments:
>
> @@ -67,6 +67,11 @@
> Django currently uses an ugly hack to restore the ordering of
> members in database models.
>
> +- The RawConfigParser class accepts a ``dict_type`` argument that
> + allows an application to set the type of dictionary used internally.
> + The motivation for this addition was expressly to allow users to
> + provide an ordered dictionary. [1]_
> +
> - Code ported from other programming languages such as PHP often
> depends on a ordered dict. Having an implementation of an
> ordering-preserving dictionary in the standard library could ease
> @@ -106,34 +111,37 @@
>
> New methods not available on dict:
>
> - ``odict.byindex(index)``
> +``odict.byindex(index)``
>
> - Index-based lookup is supported by ``byindex()`` which returns
> - the key/value pair for an index, that is, the "position" of a
> - key in the ordered dict. 0 is the first key/value pair, -1
> - the last.
> + Returns the key/value pair for an index, that is, the "position" of a key in
> + the ordered dict. 0 is the first key/value pair, -1 the last.
>
> - >>> d.byindex(2)
> - ('foo', 'bar')
> + >>> d.byindex(2)
> + ('foo', 'bar')
>
> - ``odict.sort(cmp=None, key=None, reverse=False)``
> + If there is no key for index an `IndexError` is raised.
>
> - Sorts the odict in place by cmp or key. This works exactly
> - like ``list.sort()``, but the comparison functions are passed
> - a key/value tuple, not only the value.
> +``odict.index(key)``
>
> - >>> d = odict([(42, 1), (1, 4), (23, 7)])
> - >>> d.sort()
> - >>> d
> - collections.odict([(1, 4), (23, 7), (42, 1)])
> + Returns the index of a key. If the key does not exist, a `ValueError` is
> + raised.
Hmm, while I can see the rationale for suggesting ValueError here for
the symmetry with list, KeyError is probably more intuitive.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-checkins
mailing list