diff --git a/pep-0372.txt b/pep-0372.txt index 93a13df9c..de4d79de8 100644 --- a/pep-0372.txt +++ b/pep-0372.txt @@ -135,10 +135,10 @@ constructor? The same as for regular dicts: The latter item overrides the former. This has the side-effect that the position of the first - key is used because only the value is actually overwritten: + key is used because only the value is actually overwritten:: - >>> odict([('a', 1), ('b', 2), ('a', 3)]) - collections.odict([('a', 3), ('b', 2)]) + >>> odict([('a', 1), ('b', 2), ('a', 3)]) + collections.odict([('a', 3), ('b', 2)]) This behavior is consistent with existing implementations in Python, the PHP array and the hashmap in Ruby 1.9. @@ -183,7 +183,7 @@ Does odict support alternate sort orders such as alphabetical? How well does odict work with the json module, PyYAML, and ConfigParser? - For json, the good news is that json's encoder respects odict's iteration order: + For json, the good news is that json's encoder respects odict's iteration order:: >>> items = [('one', 1), ('two', 2), ('three',3), ('four',4), ('five',5)] >>> json.dumps(OrderedDict(items)) @@ -193,13 +193,13 @@ How well does odict work with the json module, PyYAML, and ConfigParser? dictionary so order is lost before the object hook sees it. This problem is being fixed for Python 2.7/3.1 by adding an new hook that preserves order (see http://bugs.python.org/issue5381 ). - With the new hook, order can be preserved: + With the new hook, order can be preserved:: >>> jtext = '{"one": 1, "two": 2, "three": 3, "four": 4, "five": 5}' >>> json.loads(jtext, object_pairs_hook=OrderedDict) OrderedDict({'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5}) - For PyYAML, a full round-trip is problem free: + For PyYAML, a full round-trip is problem free:: >>> ytext = yaml.dump(OrderedDict(items)) >>> print ytext @@ -213,8 +213,8 @@ How well does odict work with the json module, PyYAML, and ConfigParser? >>> yaml.load(ytext) OrderedDict({'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5}) - For the ConfigParser module, round-tripping is problem free. Custom - dicts were added in Py2.6 specifically to support ordered dictionaries: + For the ConfigParser module, round-tripping is problem free. Custom + dicts were added in Py2.6 specifically to support ordered dictionaries:: >>> config = ConfigParser(dict_type=OrderedDict) >>> config.read('myconfig.ini')