Read YAML file as list
The latest YAML specification (1.2, from 2009) is quite explicit that keys in a mapping cannot be duplicated:
The content of a mapping node is an unordered set of key: value node pairs, with the restriction that each of the keys is unique.
As presented your file is not a valid YAML file and loading it should give you
a DuplicateKeyError
.
Since you know what you want to get, the easiest way to see what YAML would load like that is to dump the data structure:
import sys
import ruamel.yaml
yaml = ruamel.yaml.YAML()
data = [
{'a':{'b': 1 }},
{'a':{'b': 2, 'c': 1 }},
{'a':{'b': 3 }}
]
yaml.dump(data, sys.stdout)
which gives:
- a:
b: 1
- a:
b: 2
c: 1
- a:
b: 3