Accessing a particular list of the key
This is more or less the first two methods combined, where using the key the value list is iterated.
Example: Accessing a particular list of the key
Python3
# Creating dictionary which contains lists country = { "India" : [ "Delhi" , "Maharashtra" , "Haryana" , "Uttar Pradesh" , "Himachal Pradesh" ], "Japan" : [ "Hokkaido" , "Chubu" , "Tohoku" , "Shikoku" ], "United States" : [ "New York" , "Texas" , "Indiana" , "New Jersey" , "Hawaii" , "Alaska" ] } for i in country[ 'Japan' ]: print (i) for i in country[ 'India' ]: print (i) for i in country[ 'United States' ]: print (i) |
Output:
Hokkaido
Chubu
Tohoku
Shikoku
Delhi
Maharashtra
Haryana
Uttar Pradesh
Himachal Pradesh
New York
Texas
Indiana
New Jersey
Hawaii
Alaska
Python – Accessing Items in Lists Within Dictionary
Given a dictionary with values as a list, the task is to write a python program that can access list value items within this dictionary.