Lesson 4 · Data analytics zero to hero
Python Lists, Tuples, Sets & Dicts Explained | Data Analytics #4
Video four of the 30-part series: lists, dictionaries, tuples, and sets, the containers every real dataset ends up living in before pandas takes over.…
- CourseData analytics zero to hero
- Lesson4 of 30
- Video11 min
- FormatJupyter notebook · 10 code cells
What you'll learn
Data
No separate download needed — the notebook creates or downloads everything it uses.
📓 Full notebook
Download .ipynbData Analytics Zero to Hero, Video 4: Data Structures#
- Video four of the 30-part series: lists, dictionaries, tuples, and sets, the containers every real dataset ends up living in before pandas takes over.
- Builds on functions and control flow from videos two and three.
- Let's jump straight in.
Before You Start#
- Open a new Jupyter Notebook in VS Code and select your Python interpreter as the kernel.
Part 1: Lists#
car_models = ['Mazda RX4', 'Datsun 710', 'Hornet 4 Drive', 'Duster 360']
print(car_models)
print(len(car_models))
print(car_models[0])
print(car_models[-1])
car_models.append('Valiant')
print(car_models)
car_models.remove('Datsun 710')
print(car_models)
car_models[0] = 'Mazda RX4 Wag'
print(car_models)
mpg_values = [21.0, 22.8, 21.4, 18.7, 18.1]
print(sorted(mpg_values))
print(sorted(mpg_values, reverse=True))
print(sum(mpg_values) / len(mpg_values))
Part 2: Dictionaries#
car = {'model': 'Mazda RX4', 'mpg': 21.0, 'cyl': 6, 'hp': 110}
print(car)
print(car['model'])
print(car['mpg'])
car['transmission'] = 'manual'
print(car)
print(car.get('weight', 'unknown'))
print(car.keys())
print(car.values())
A List of Dictionaries#
cars = [
{'model': 'Mazda RX4', 'mpg': 21.0, 'cyl': 6},
{'model': 'Datsun 710', 'mpg': 22.8, 'cyl': 4},
{'model': 'Duster 360', 'mpg': 14.3, 'cyl': 8}
]
for car in cars:
print(f"{car['model']}: {car['mpg']} mpg, {car['cyl']} cylinders")
Part 3: Tuples#
dimensions = (17.02, 2.62)
print(dimensions)
print(dimensions[0])
qsec, weight = dimensions
print(qsec, weight)
try:
dimensions[0] = 99
except TypeError as e:
print('Error:', e)
Part 4: Sets#
cylinder_counts = [6, 4, 8, 6, 4, 4, 8, 6]
unique_cylinders = set(cylinder_counts)
print(unique_cylinders)
print(len(unique_cylinders))
four_cyl_models = {'Datsun 710', 'Merc 240D', 'Fiat 128'}
efficient_models = {'Datsun 710', 'Fiat 128', 'Toyota Corolla'}
print(four_cyl_models & efficient_models)
print(four_cyl_models | efficient_models)
print(four_cyl_models - efficient_models)
Wrap-Up: What You Learned#
- Lists: ordered and changeable, with indexing, append, remove, and sorting.
- Dictionaries: key-value pairs, plus a list of dictionaries as a mental model for a full dataset.
- Tuples: ordered but immutable, and how they relate to unpacking multiple return values.
- Sets: unique, unordered values, plus intersection, union, and difference.
- These four containers are the foundation pandas itself is built on top of. Video five covers reading and writing real CSV, text, and JSON files, so subscribe if you want it to land automatically.
Found this useful?
All lessons, notebooks and datasets here are free. If they helped you, a coffee keeps new lessons coming.



