By the end of this lesson, learners will understand the differences between lists, tuples, and dictionaries in Python, and how to use them effectively in data engineering tasks.

Lists

What is a List?

A list is an ordered, mutable collection of items. Think of it like a flexible container that can grow, shrink, and change.

fruits = ["apple", "banana", "cherry"]

Key Features:

  • Ordered

  • Mutable (can be changed)

  • Allows duplicates

Common Use Cases:

  • Storing rows of data

  • Collecting values from a loop

  • Building dynamic datasets

Example in Data Engineering:

Reading and storing data from a file.

import csv

# 1) Write a small CSV file
with open("dummy_file.csv", "w", newline="") as f:
    writer = csv.writer(f)
    writer.writerow(["col1", "col2", "col3"])
    writer.writerow([1, 2, 3])
    writer.writerow([4, 5, 6])

# 2) Read the CSV file into a list of rows
data_rows = []
with open("dummy_file.csv", "r", newline="") as f:
    reader = csv.reader(f)
    for row in reader:
        data_rows.append(row)

# 3) Show the result
print(data_rows)

Tuples

What is a Tuple?

A tuple is an ordered, immutable collection. Once created, it cannot be changed.

coordinates = (45.0, -73.5)

Key Features:

  • Ordered

  • Immutable

  • Faster than lists for fixed data

Common Use Cases:

  • Storing fixed-size records (e.g., coordinates, config values)

  • Returning multiple values from a function

Example in Data Engineering:

Returning multiple values from a function.

# A tuple representing a customer data record: (Customer ID, last name, first name, registration date)
client_record = (101, "Dupont", "Jean", "2023-10-27")

# Display the record
print(client_record)

# Access specific elements
client_id = client_record[0]
date_enregistrement = client_record[3]

print(f"Client ID: {client_id}")
print(f"Registration Date: {date_enregistrement}")

Dictionaries

What is a Dictionary?

A dictionary is an unordered, mutable collection of key-value pairs. It’s like a mini database in memory.

user = {"name": "Alice", "role": "Data Engineer", "active": True}

Key Features:

  • Key-value structure

  • Fast lookups

  • Mutable

Common Use Cases:

  • Storing metadata

  • Mapping column names to values

  • Building JSON-like structures

Example in Data Engineering:

 Representing a record in a data pipeline.

record = {
    "id": 101,
    "timestamp": "2025-09-07T10:00:00",
    "status": "processed"
}

Summary

Structure Ordered Mutable Use Case
List
Dynamic collections
Tuple
Fixed records
Dictionary
Structured key-value data