Skip to content

Instantly share code, notes, and snippets.

  • Select an option

  • Save LizaPiya/7e8c1d0f6c25a4275a1b65241f65b0ed to your computer and use it in GitHub Desktop.

Select an option

Save LizaPiya/7e8c1d0f6c25a4275a1b65241f65b0ed to your computer and use it in GitHub Desktop.
Getting Started with Dictionaries
Create a dictionary that keeps track of the USA’s Olympic medal count. Each key of the dictionary should be the type of medal (gold, silver, or bronze) and each key’s value should be the number of that type of medal the USA’s won. Currently, the USA has 33 gold medals, 17 silver, and 12 bronze. Create a dictionary saved in the variable medals that reflects this information.
medals={}
medals['gold']=33
medals['silver']=17
medals['bronze']=12
print (medals)
You are keeping track of olympic medals for Italy in the 2016 Rio Summer Olympics! At the moment, Italy has 7 gold medals, 8 silver metals, and 6 bronze medals. Create a dictionary called olympics where the keys are the types of medals, and the values are the number of that type of medals that Italy has won so far.
olympics={}
olympics['gold']=7
olympics['silver']=8
olympics['bronze']=6
print (olympics)
## Update the value for “Phelps” in the dictionary swimmers to include his medals from the Rio Olympics by adding 5 to the current value (Phelps will now have 28 total medals). Do not rewrite the dictionary.
swimmers = {'Manuel':4, 'Lochte':12, 'Adrian':7, 'Ledecky':5, 'Dirado':4, 'Phelps':23}
swimmers['Phelps']=swimmers['Phelps']+5
## We have a dictionary of the specific events that Italy has won medals in and the number of medals they have won for each event. Assign to the variable events a list of the keys from the dictionary medal_events. Do not hard code this.
medal_events = {'Shooting': 7, 'Fencing': 4, 'Judo': 2, 'Swimming': 3, 'Diving': 2}
events=medal_events.keys()
4. Every four years, the summer Olympics are held in a different country. Add a key-value pair to the dictionary places that reflects that the 2016 Olympics were held in Brazil. Do not rewrite the entire dictionary to do this!
places = {"Australia":2000, "Greece":2004, "China":2008, "England":2012}
places["Brazil"]=2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment