Home > Articles

  • Print
  • + Share This
This chapter is from the book

What Dictionaries Can Do

A dictionary is another example of a data structure, and, like a list, it is one of the most commonly used data structures in programming. A dictionary is used to map or associate things you want to store to keys you need to get them. Again, programmers don’t use a term like “dictionary” for something that doesn’t work like an actual dictionary full of words, so let’s use that as our real world example.

Let’s say you want to find out what the word “honorificabilitudinitatibus” means. Today you would simply copy-paste that word into a search engine and then find out the answer, and we could say a search engine is like a really huge super complex version of the Oxford English Dictionary (OED). Before search engines what you would do is this:

  1. Go to your library and get “the dictionary.” Let’s say it’s the OED.

  2. You know “honorificabilitudinitatibus” starts with the letter “H” so you look on the side of the book for the little tab that has “H” on it.

  3. Skim the pages until you are close to where “hon” starts.

  4. Skim a few more pages until you find “honorificabilitudinitatibus” or hit the beginning of the “hp” words and realize this word isn’t in the OED.

  5. Once you find the entry, you read the definition to figure out what it means.

This process is nearly exactly the way a dict works, and you are basically “mapping” the word “honorificabilitudinitatibus” to its definition. A dict in Python is just like a dictionary in the real world such as the OED.

  • + Share This
  • 🔖 Save To Your Account