bpo-36060: Document how collections.ChainMap() determines iteration o… · python/cpython@7121a6e (original) (raw)

`@@ -100,6 +100,21 @@ The class can be used to simulate nested scopes and is useful in templating.

`

100

100

``` :func:super function. A reference to d.parents is equivalent to:


`101`

`101`

```  ``ChainMap(*d.maps[1:])``.

102

102

``

``

103

`` +

Note, the iteration order of a :class:ChainMap() is determined by

``

``

104

`+

scanning the mappings last to first::

`

``

105

+

``

106

`+

baseline = {'music': 'bach', 'art': 'rembrandt'}

`

``

107

`+

adjustments = {'art': 'van gogh', 'opera': 'carmen'}

`

``

108

`+

list(ChainMap(adjustments, baseline))

`

``

109

`+

['music', 'art', 'opera']

`

``

110

+

``

111

`` +

This gives the same ordering as a series of :meth:dict.update calls

``

``

112

`+

starting with the last mapping::

`

``

113

+

``

114

`+

combined = baseline.copy()

`

``

115

`+

combined.update(adjustments)

`

``

116

`+

list(combined)

`

``

117

`+

['music', 'art', 'opera']

`

103

118

``

104

119

`.. seealso::

`

105

120

``