Python 101: All About Dictionaries

See the original posting on DZone Python

The Python programming language has several built-in types that it supports. One of my favorites is the dictionary. A dictionary is a mapping object that maps hashable values to arbitrary objects (source). Other languages call dictionaries “hash tables.” They are mutable objects that you can change whenever you want to, unlike tuples. A dictionary’s keys must be hashable or immutable, which means that you cannot use a list or another dictionary as a key. Note that dictionaries are not ordered. What this means is that when you iterate over a dictionary, you may not extract the values in the same order that you inserted them.

In this article, we will take some time to learn about some of the many things you can do with a dictionary.