Working with dictionaries and lists
Before we get too deep into dictionaries and lists, it’s important to note that Python does not contain arrays in the built-in functions. We can use lists and perform a lot of the traditional functions on lists that we’d use for arrays. However, for more robust functionalities with arrays, a library is needed, such as NumPy.
Python has four collection data types or arrays. The four collection data types in Python are listed as follows:
- Lists: Ordered and changeable; can have duplicates
- Tuples: Ordered and unchangeable; can have duplicates
- Sets: Unordered and unindexed; cannot have duplicates
- Dictionaries: Unordered, changeable, and indexed; cannot have duplicates
As noted, we won’t be going into NumPy libraries or other data libraries just yet. For now, we’re going to focus on dictionaries and lists.
Defining and using dictionaries
You may recall that we used dictionaries in Chapter...