Jaffa's Reflection on Dictionaries

by Jaffa

08 Jun 2017

Dictionaries seem really useful, but I am not sure that I understand how exactly to use them. There are a couple of things that I find interesting about them. When I ran the first print statement from the state dictionary exercise, I was alarmed that the states on my screen were in a different order than the states on the projector. I guess that means that you can’t index them in the same way that you do for lists. Even though you can’t refer to keys in the dictionary by index, you can refer to values by their associated keys.

Dictionaries also allow you to create a dictionary of different values for a single key. This would be useful so that a single key can have values with different types that you could use in different situations, but all refer to the same key. That is speculation on my part, but it seems reasonable to me. If it doesn’t work that way, maybe the Python developers should think about implementing something like that. Finally, the in operator’s use of different algorithms for lists and dictionaries interests me. This means that the time it takes to search a list increases as the list increases in length. Dictionaries do not take longer based on length so they are more efficient.

Jaffa is a rising second-year MSIS student. She has lived in 6 different states. Find Jaffa on Twitter, Github, and on the web.