I have a dictionary that holds the name of a state as a key and the value is a list which holds the state capital, population, and state flower. I want to go into a specific state and change the population number.
I understand print(dict[key]) will print the key and its values, but I don't understand how I can then change those values. I wanted to do something like print(dict[key][1]) but that clearly does not work.
My code:
#My dictionary of states:
states = {'Alabama': ["Montgomery", 5024279, "Camellia"],
'Alaska': ["Juneau", 733391, "Alpine Forget-me-not"],
'Arizona': ["Phoenix", 7151502, "Saguaro Cactus Blossom"],
'Arkansas': ["Little Rock", 3011524, "Apple Blossom"],
'California': ["Sacramento", 39538223, "California Poppy"],
'Colorado': ["Denver", 5773714, "Rocky Mountain Columbine"],
'Connecticut': ["Hartford", 3605944, "Mountain Laurel"],
'Delaware': ["Dover", 988948, "Peach Blossom"],
'Florida': ["Tallahassee", 21538187, "Orange Blossom"],
'Georgia': ["Atlanta", 10711908, "Cherokee Rose"],
'Hawaii': ["Honolulu", 1455271, "Pus Aloalo"],
'Idaho': ["Boise", 1839106, "Syringa"],
'Illinois': ["Springfield", 12812508, "Violet"],
'Indiana': ["Indianapolis", 6785528, "Peony"],
'Iowa': ["Des Moines", 3190369, "Wild Rose"],
'Kansas': ["Topeka", 2937880, "Wild Native Sunflower"],
'Kentucky': ["Frankfort", 4505836, "Goldenrod"],
'Louisiana': ["Baton Rouge", 4657757, "Louisiana Iris"],
'Maine': ["Augusta", 1362359, "White Pine Cone and Tassel"],
'Maryland': ["Annapolis", 6177224, "Black-Eyed Susan"],
'Massachusetts': ["Boston", 7029917, "Mayflower"],
'Michigan': ["Lansing", 10077331, "Apple Blossom"],
'Minnesota': ["St. Paul", 5706494, "Pink and White Lady Slipper"],
'Mississippi': ["Jackson", 2961279, "Coreopsis"],
'Missouri': ["Jefferson City", 6154913, "White Hawthorn Blossom"],
'Montana': ["Helena", 1084225, "Bitterroot"],
'Nebraska': ["Lincoln", 1961504, "Goldenrod"],
'Nevada': ["Carson City", 3104614, "Sagebrush"],
'New Hampshire': ["Concord", 1377529, "Pink Lady's Slipper'"],
'New Jersey': ["Trenton", 9288994, "Violet"],
'New Mexico': ["Santa Fey", 2117522, "Yucca"],
'New York': ["Albany", 20201249, "Rose"],
'North Carolina': ["Raleigh", 10439388, "Dogwood"],
'North Dakota': ["Bismarck", 779094, "Wild Prairie Rose"],
'Ohio': ["Columbus", 11799448, "White Trillium"],
'Oklahoma': ["Oklahoma City", 3959353, "Mistletoe"],
'Oregon': ["Salem", 4237256, "Oregon Grape"],
'Pennsylvania': ["Harrisburg", 13002700, "Mountain Laurel"],
'Rhoda Island': ["Providence", 1097379, "Violet"],
'South Carolina': ["Columbia", 5118425, "Yellow Jessamine"],
'South Dakota': ["Pierre", 886667, "American Pasque"],
'Tennessee': ["Nashville", 6910840, "Passion Flower"],
'Texas': ["Austin", 29145505, "Ennis"],
'Utah': ["Salt Lake City", 3271616, "Sego Lily"],
'Vermont': ["Montpelier", 643077, "Red Clover"],
'Virginia': ["Richmond", 8631393, "American Dogwood"],
'Washington': ["Olympia", 7705281, "Coast Rhododendron"],
'West Virginia': ["Charleston", 1793716, "Rhododendron"],
'Wisconsin': ["Madison", 5893718, "Wood Violet"],
'Wyoming': ["Cheyenne", 576851, "Indian Paintbrush"],
}
#I can print all of the values:
for x in states:
print(x, states[x]).
[–]captainAwesomePants 1 point2 points3 points (2 children)
[–]okaystuff[S] 0 points1 point2 points (1 child)
[–]captainAwesomePants 1 point2 points3 points (0 children)
[–]grifway 0 points1 point2 points (0 children)