python - How do I retrieve a list within dictionary within a list? -
how retrieve list value, within dictionary, that's within list?
x = [{'name': 'joe', 'items': ['hat','scarf','boots']}, {'name': 'john', 'items': ['jeans','shirt','jacket']}]
x considered list type variable, , i'm trying pull values within list called 'items'.
calling x[0] load first list item includes name , items joe, not sure how pull items. x[0][0] of course doesn't work because it's part of dictionary.
you access think intuitively. access first element in list, , list element @ index 0 respective dict:
>>> print(x[0]['items'][0]) hat
the logical progression
>>> print(x[0]) {'name': 'joe', 'items': ['hat', 'scarf', 'boots']} >>> print(x[0]['items']) ['hat', 'scarf', 'boots'] >>> print(x[0]['items'][0]) hat