📄️ A Preface to Data Structures in Python
Before we get started, we should address a few important terms that will be used in this lesson.
📄️ Lists
A key concept in programming is Lists (similar to the well known Array). A list is a data structure that allows you to store collection of data next to each other in memory. Then, you are able to access this data by using an index. Lists are also ordered, this means that all elements of a list will maintain their order (ex: [1, 2, 3] . The first value here will always be the first, it will not change order). They are also mutable and can be modified by adding, removing, or changing elements.
📄️ Tuples
Another important data structure in Python is the Tuple. A tuple is a data structure that allows you to store a collection of data next to each other in memory (just like a list)! Then, you are able to access this data by using an index. Tuples are also ordered, meaning that all elements of a tuple will maintain their order. However, tuples have a minor difference from lists: they are immutable, meaning that once you create a tuple, you cannot change its contents. This makes tuples a great choice for storing data that should not be modified.
📄️ Dictionaries
Dictionaries, also known as associative arrays or hash maps, are a built-in data structure in Python that store data in key-value pairs. They are pretty versatile and allow for fast lookups, insertions, and deletions. Dictionaries are mutable, meaning you can change their contents after creation. It is important to note that dictionaries are unordered collections, meaning the order of items is not guaranteed.
📄️ Sets
Sets are a type of collection in Python that store unique elements. Think of a set like a bag where you can only have one of each item and no duplicates are allowed. Sets are useful when you need to work with unique items or perform operations like finding common elements between collections.