If I have a dictionary that looks like:
{'first': [
{'red': ['six', 'three', 'seven', 'six']},
{'green': ['eight', 'three', 'four']}
],
'second': [
{'blue': ['one', 'five', 'three']}
]
}
How can I get to specific points in the dictionary? For example, how can I print out the second ‘six’ in the ‘first’ header under subheading ‘red’?
Assuming your dictionary is called
dyou could do this:d['first']gives you the value associated with the key'first'. The value is a list.[0]gives you the first element in the list (by the way, why do you have a list containing only one element?). Note that indexing is 0-based in Python.['red']fetches the value from this dictionary.[3]accesses the fourth element in the list.