A Professional’s Tutorial to Python Lists
Welcome to second, in a series of tutorials that teach beginner Python specifically for aspiring data scientists. For an overview of these tutorials, click here.
In our daily lives, we frequently utilize lists to bring order to chaos.
- A list for groceries might remind us to buy milk, eggs, and bread.
- A to-do list might prioritize tasks for the day.
- A recipe list breaks down ingredients for a delectable dish.
These everyday lists, essentially, are linear collections of items that serve to guide our actions or jog our memories.
A Python list, at a high level, can be thought of in a similar manner — it’s a linear collection of items. However, the analogy begins to diverge sharply when we examine the intricacies and capabilities of Python lists.
Here are some more thoughts on how to think (🤔 💭 🧐 ) about Python lists.
- Firstly, while our everyday lists typically follow a theme or purpose (e.g., ingredients for a recipe), a Python list can comprise items of disparate data types: numbers, strings, and even other lists or data structures. This thematic cohesion is akin to having a shopping list that not only tells you which groceries to buy but also includes tasks for the day and reminders for the week — all in a single list.
- Secondly, Python lists are far more dynamic. Imagine an everyday list that can reorder itself based on specific criteria, automatically remove duplicates, or instantly tell you the number of items it contains. A Python list comes with built-in functionalities that allow for such manipulations, and many more.
- Lastly, while everyday lists are tools for human comprehension and recollection, Python lists are built for machine operations. They are designed to be iterated over, manipulated, and used as building blocks for more advanced data structures and algorithms.