Dictionary Exercise

by Maddy

06 Jun 2018

Dictionary Exercise

As done in class

This dictionary exercise was particularly complex. I appreciate that we got to go over this as a class. I don’t think I would have been able to figure out a lot of this stuff otherwise. One of the trickiest thing for me to wrap my head around right now is the state_dict[state] format. I can think through this and determine the square brackets are referencing an index within the dictionary, but just looking at that doesn’t quite register immediately. I also struggle to wrap my head around the following code:

for state in states_list:
  print(state, "\t\t", states_dict[state])

I don’t quite understand how states_dict[state] produces the list of values rather than the name of the states. I know that the code directly before it incremented the states, I just don’t quite understand how states_dict[state] stored the values that were incremented.

I can definitely see how using dictionaries as opposed to lists can be useful, but I will definitely need some more practice with using dictionaries before I feel confident with these techniques.

Here’s the program I wrote out while we went over this in class:

Maddy is a Professional Science Master's student at UNC-Chapel Hill studying Biomedical & Health Informatics. Find Maddy on Twitter, Github, and on the web.