I have an nested OrderedDict data:
OrderedDict([('6',
OrderedDict([('idx2', ['6', '6', '6']),
('val2', ['A', 'T', 'T']),
('val1', ['C', 'A', 'T']),
('pos', ['11', '15', '23']),
('idx1', ['4', '4', '4'])])),
('3',
OrderedDict([('idx2', ['3', '3']),
('val2', ['G', 'C']),
('val1', ['A', 'G']),
('pos', ['28', '34']),
('idx1', ['4', '4'])])),
('4',
OrderedDict([('idx2', ['4', '4']),
('val2', ['T', 'C']),
('val1', ['C', 'C']),
('pos', ['41', '51']),
('idx1', ['4', '4'])]))])
I can access the key, value
pairs for each keys like:
for k, v in grouped_data.items():
print(k, v)
and further nests using:
for k, v in grouped_data.items():
print(k, v)
for x in v.items():
print(x)
for z in x:
print(z)
But, to process my data I need to access two consecutive keys at a time in a for loop: first 6-3 and then 3-4 and so on until the end.
I was thinking if I can index the key and get the keys, values after it:
for k, v in grouped_data.items():
print(k, v)
ind = grouped_data.keys().index(k)
Or,
for k, v in grouped_data.items():
print(k, v)
print(next(k))