Python Lists
Store, access and manipulate collections of data with Python lists
Lists are the most common Python data structure. A list is an ordered collection of items — numbers, strings, or a mix. In data analysis, you use lists to store column names, filter values, file paths, category labels, and more.
Lists are mutable (you can change them) and allow duplicates. They are indexed starting at 0. Understanding lists is the foundation for understanding how Pandas DataFrames work under the hood.
Examples
Key Points
- ✓Index starts at 0: list[0] is the first item, list[-1] is the last
- ✓Slicing list[start:end] — end is exclusive: list[1:3] gives items at index 1 and 2
- ✓append() adds one item; extend() adds all items from another list
- ✓List comprehensions are faster than for loops for simple transformations
- ✓In Pandas, df.columns.tolist() returns column names as a Python list
Practice Question
What does scores[-1] return if scores = [85, 92, 78, 95]?
Related Topics
Tuples and SetsUse tuples for fixed data and sets for unique value operationsDictionaries in PythonKey-value pairs for fast lookups, mappings and structured dataLoops — for and whileIterate over data, automate repetitive tasks, and process multiple files with loopsNumPy ArraysFast numerical computation with NumPy arrays — the engine behind Pandas