I have a list of dicts coming from a yaml file. Each dict has nested lists of dicts that I can read as below:
import yaml
stream = open('KK_20130701_003_19844.yaml','r')
data = []
data.append(yaml.load(stream))
for rows in data:
print rows['peaks']
{'peaks':
[{'intensity': [1217.956975, 1649.030477, 7081.000197,... 15225.865077, 15230.394569, 20125.554444],
'z': [1, 1, 1, ... 24, 24, 24],
'scans': [{'z': 0.0, 'id': 19844, 'mz': 0.0}]}],
'scan': [{'z': 0.0, 'id': 19844, 'mz': 0.0}]
}
I am not sure what the best way is to each of the elements in the nested lists and the nested dicts in the lists. If I try to read them as dicts i get the following typeerror: TypeError: list indices must be integers, not str