Introduction to Data Structures in
Python – Class Lecture Notes
Prepared as an academic resource
Table of Contents
Introduction
Data structures are fundamental constructs that organize and store data efficiently. Python
provides several built-in data structures such as lists, tuples, sets, and dictionaries.
Learning Objectives
- Understand basic data structures in Python
- Learn the usage and performance of lists, tuples, sets, and dictionaries
- Implement simple use-cases for each structure
Overview of Structures
1. List – ordered, mutable, allows duplicates
2. Tuple – ordered, immutable
3. Set – unordered, unique elements
4. Dictionary – key-value pairs, fast lookup
Example Code
# Lists
fruits = ["apple", "banana", "cherry"]
fruits.append("orange")
# Tuples
colors = ("red", "green", "blue")
# Sets
unique_numbers = {1, 2, 2, 3}
# Dictionaries
student = {"name": "Alice", "age": 22}
print(student["name"])
Summary
Choosing the correct data structure is essential for performance and readability. Python
makes it easy to work with built-in structures.
Review Questions
- What are the key differences between lists and tuples?
- How do sets handle duplicate values?
- When should you use a dictionary?