Reputation: 1487
I have following data structure:
mydic = {
'q4a1_0' : {'title':'4 Question 1 Answer (01)','choices': ((0,'Very Bad'),(1,'Medium'),(2,'Good'),(3,'Very Good'))},
'q3a1_0' : {'title':'3 Question 1 Answer (01)','choices': ((0,'Very Bad'),(1,'Good'),(2,'Very Good'))}
}
My question is how can I access 'choices' or 'titles' of any dictionary keys(say 'q4a1_0') directly.
Upvotes: 2
Views: 289
Reputation: 47012
mydic
is a dictionary, which has a dictionary in it. So mydic['q4a1_0']
gets you to the inner dictionary, and mydic['q4a1_0']['title']
would get you the title
key from q4a1_0
.
Upvotes: 2
Reputation: 6404
Access by using the indices.
>>> mydic['q4a1_0']['choices']
((0, 'Very Bad'), (1, 'Medium'), (2, 'Good'), (3, 'Very Good'))
Upvotes: 3