Home > Articles

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.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.