# A list of computer science pioneers
pioneers = ["Grace Hopper", "Ada Lovelace", "Katherine Johnson"]
# Add new pioneer (append adds to the end)
pioneers.append("Dorothy Vaughan")
# Update an item (zero-based indexing)
pioneers[0] = "Rear Admiral Grace Hopper"
# Insert at specific position
pioneers.insert(1, "Hedy Lamarr")
print(pioneers)
# Output: ['Rear Admiral Grace Hopper', 'Hedy Lamarr', 'Ada Lovelace', 'Katherine Johnson', 'Dorothy Vaughan']
# Useful list methods
print(f"Number of pioneers: {len(pioneers)}")
print(f"Last pioneer: {pioneers[-1]}")IS 4010: Application Development with Artificial Intelligence
Week 04: Python data structures
Brandon M. Greenwell
Welcome to Python data structures
The foundation of organized programming
- Data structures organize values for particular operations
- They determine how we organize, store, and access information
- Built-in choices: Python provides lists, tuples, dictionaries, and sets
- Program design: The representation you choose affects clarity, correctness, and performance
- Practical impact: Lists, dictionaries, tuples, and sets solve different data problems
Session 1: sequences and collections
What is a data structure?
- A data structure is a way to organize and store multiple pieces of data in a single variable
- Think of them as specialized containers for your data
- Python’s built-in collections: Lists, tuples, dictionaries, and sets
- Choosing deliberately: Match the representation to the operations and invariants you need
- Performance matters: Different structures excel at different operations
The list: a mutable sequence
- A list is an ordered, changeable collection of items
- Most versatile: Lists are the workhorses of Python programming
- Ordered: Items maintain their position - first in, stays first (unless you change it)
- Mutable: Add, remove, or modify items after creation
- Syntax: Items enclosed in square brackets
[], separated by commas - Dynamic size: Grow or shrink as needed - no fixed size limit
Your turn: practice with lists
Create your own list and practice the operations:
# TODO: Create a list of your favorite programming languages
my_languages = []
# TODO: Add at least 3 languages to your list
# TODO: Print the list and its length
# TODO: Access the first and last items
# TODO: Insert a new language at position 1
# TODO: Remove the last language and print what was removedThe tuple: an immutable sequence
- A tuple is an ordered, unchangeable collection of items
- Ordered: Like lists, items maintain their position
- Immutable: Cannot add, remove, or change items after creation
- Syntax: Items enclosed in parentheses
(), though parentheses are often optional - Use cases: Coordinates, RGB colors, database records, function return values
- Performance advantage: Slightly faster than lists for accessing elements
- Memory efficient: Less overhead than lists due to immutability
# Coordinate pairs for a map application
start_location = (39.1031, -84.5120) # Cincinnati coordinates
end_location = (39.7391, -104.9847) # Denver coordinates
# RGB color values for UI design
brand_colors = (
(0, 123, 191), # UC Blue
(224, 18, 34), # UC Red
(0, 0, 0) # Black
)
# Tuple unpacking (very common pattern)
lat, lon = start_location
print(f"Starting at latitude {lat}, longitude {lon}")
# Multiple return values from functions
def get_name_and_grade():
return "Alice", 95.5 # Returns a tuple
name, grade = get_name_and_grade() # Tuple unpacking
# Single item tuple (note the comma!)
single_item = (42,) # Without comma, it's just parentheses for groupingYour turn: practice with tuples
# TODO: Create a tuple representing your favorite restaurant's location (name, latitude, longitude)
# TODO: Unpack the tuple into separate variables
# TODO: Print a formatted message about the restaurant
# TODO: Create a function that returns multiple pieces of information about yourself
# (name, major, year, favorite_color) and unpack the result
# TODO: Call the function and unpack the resultsAccessing items: indexing and slicing
- Zero-based indexing: Python counts from 0, not 1 (like most programming languages)
- Positive indices:
my_list[0]first item,my_list[1]second item, etc. - Negative indices:
my_list[-1]last item,my_list[-2]second-to-last, etc. - Slicing: Extract ranges of items with
start:stop:stepsyntax - Slice behavior:
[start:stop]includes start, excludes stop - Advanced slicing: Control step size and direction
# Working with sequence data
languages = ["Python", "JavaScript", "Java", "C++", "Rust", "Go", "TypeScript"]
# Basic indexing
print(f"First language: {languages[0]}") # Python
print(f"Third language: {languages[2]}") # Java
print(f"Last language: {languages[-1]}") # TypeScript
print(f"Second to last: {languages[-2]}") # Go
# Slicing examples
print(f"First three: {languages[0:3]}") # ['Python', 'JavaScript', 'Java']
print(f"From index 2 on: {languages[2:]}") # ['Java', 'C++', 'Rust', 'Go', 'TypeScript']
print(f"Last three: {languages[-3:]}") # ['Rust', 'Go', 'TypeScript']
print(f"Every other: {languages[::2]}") # ['Python', 'Java', 'Rust', 'TypeScript']
print(f"Reversed: {languages[::-1]}") # Entire list in reverse order
# Slicing with coordinates
point = (10, 20, 30, 40)
x, y = point[0:2] # Get first two values
print(f"2D coordinates: ({x}, {y})")Common sequence operations
- Length:
len(sequence)returns number of items - Membership:
item in sequencechecks if item exists - Concatenation:
list1 + list2combines sequences - Repetition:
list * 3repeats sequence multiple times - Sorting:
sorted()returns new sorted sequence,list.sort()modifies in place - Finding:
sequence.index(item)finds first occurrence
# Working with programming languages data
popular_languages = ["Python", "JavaScript", "TypeScript"]
systems_languages = ["C++", "Rust", "Go"]
# Length and membership
print(f"We track {len(popular_languages)} popular languages")
print(f"Is Python popular? {'Python' in popular_languages}")
print(f"Is Assembly popular? {'Assembly' in popular_languages}")
# Concatenation and repetition
all_languages = popular_languages + systems_languages
separator = ["-"] * 3 # Creates ["-", "-", "-"]
# Sorting (doesn't modify original)
sorted_languages = sorted(all_languages)
print(f"Alphabetical: {sorted_languages}")
# Finding items
try:
rust_position = all_languages.index("Rust")
print(f"Rust is at position {rust_position}")
except ValueError:
print("Rust not found in list")
# List comprehensions (introduced earlier in this lecture!)
short_names = [lang for lang in all_languages if len(lang) <= 4]
print(f"Short language names: {short_names}")Quick introduction: list comprehensions
Python has a concise way to create lists called list comprehensions:
# Traditional approach with loops
numbers = []
for i in range(5):
numbers.append(i * 2)
print(numbers) # [0, 2, 4, 6, 8]
# List comprehension - more concise!
numbers = [i * 2 for i in range(5)]
print(numbers) # [0, 2, 4, 6, 8]
# Pattern: [expression for item in iterable]
emails = [f"user_{i}@email.com" for i in range(3)]
print(emails) # ['user_0@email.com', 'user_1@email.com', 'user_2@email.com']Why learn this now? - Useful for generating compact test data for the timing exercise - More readable and Pythonic than traditional loops - We’ll use this pattern extensively in data processing
Your turn: practice list comprehensions
# TODO: Create a list of squares for numbers 1-10 using a list comprehension
# TODO: Create a list of even numbers from 0-20 using a list comprehension
# TODO: Create a list of customer emails for customer IDs 100-105Live exercise: AI-assisted performance detective
Challenge: Ask an AI assistant to identify the bottleneck, then verify its claim with timing evidence.
# SLOW CODE - Let's time this together!
import time
# Simulating a large customer database
customers = [f"customer_{i}@email.com" for i in range(50000)]
vip_customers = [f"customer_{i}@email.com" for i in range(0, 50000, 100)] # Every 100th customer
# Slow approach - checking VIP status
def is_vip_slow(email, vip_list):
"""Check if customer is VIP - using list membership"""
return email in vip_list
# Let's time this approach
start_time = time.time()
vip_count = 0
for customer in customers[:1000]: # Check first 1000 customers
if is_vip_slow(customer, vip_customers):
vip_count += 1
slow_time = time.time() - start_time
print(f"Slow approach: {slow_time:.4f} seconds, found {vip_count} VIPs")Your turn with an AI assistant:
- Ask Claude/Gemini/ChatGPT: “How can I optimize this customer VIP lookup code?”
- Get timing comparison: What data structure should we use instead?
- Implement together: Let’s code the optimized version live!
Revised solution: use a set for membership
# Revised code after reviewing the suggestion
import time
# Convert VIP list to set for O(1) lookups
vip_customers_set = set(vip_customers)
def is_vip_fast(email, vip_set):
"""Check if customer is VIP - using set membership"""
return email in vip_set
# Time the optimized approach
start_time = time.time()
vip_count = 0
for customer in customers[:1000]:
if is_vip_fast(customer, vip_customers_set):
vip_count += 1
fast_time = time.time() - start_time
print(f"Fast approach: {fast_time:.4f} seconds, found {vip_count} VIPs")
print(f"Speedup: {slow_time/fast_time:.1f}x faster!")
# Follow-up: What other changes might matter at a larger scale?
# - Pre-compute VIP status in a dictionary
# - Use database indexing for larger datasets
# - Cache frequently accessed resultsResults Discussion: - Performance effect: Set membership is average-case O(1), while list membership is O(n) - AI role: Generate candidate explanations; timing results determine whether they apply here - Real impact: This optimization matters in production systems - Learning loop: AI suggestions → implementation → measurement → iteration
Session 2: mappings and collections
The dictionary: key-value pairs
- A dictionary is a collection of
key: valuepairs - Key-based lookups: Average-case O(1) retrieval when you know the key
- Real-world analogy: Like a phone book or actual dictionary - look up by name/word, get number/definition
- Unique keys: Each key can appear only once, but values can be duplicated
- Key types: Strings, numbers, tuples (immutable types only)
- Syntax: Pairs enclosed in curly braces
{key: value} - Python 3.7+: Dictionaries maintain insertion order (ordered)
# User profile for a social media application
user_profile = {
"username": "ada_lovelace",
"first_name": "Ada",
"last_name": "Lovelace",
"birth_year": 1815,
"occupation": "Mathematician",
"famous_for": "First computer programmer",
"followers": 125000,
"verified": True,
"programming_languages": ["Analytical Engine", "Mathematics"]
}
# Accessing values (multiple ways)
print(f"User: {user_profile['username']}")
print(f"Born: {user_profile.get('birth_year', 'Unknown')}") # Safe access
print(f"Followers: {user_profile['followers']:,}")
# Adding new information
user_profile["location"] = "London, England"
user_profile["last_active"] = "1852-11-27"
# Updating existing values
user_profile["followers"] += 1000 # New followers!
print(f"Updated profile: {user_profile['username']} now has {user_profile['followers']:,} followers")Live exercise: data-structure refactoring
Challenge: This code works, but positional fields make it hard to read and change.
# MESSY CODE - Student registration system (needs help!)
def process_student_data():
# Raw data from registration form
students = []
students.append(["Alice Johnson", "alice@uc.edu", "IS4010", 95])
students.append(["Bob Smith", "bob@uc.edu", "IS4010", 87])
students.append(["Alice Johnson", "alice@uc.edu", "CS2071", 92]) # Duplicate student!
students.append(["Carol Davis", "carol@uc.edu", "IS4010", 78])
students.append(["Bob Smith", "bob@uc.edu", "MATH2045", 85]) # Another duplicate!
# Find students in IS4010 (slow way)
is4010_students = []
for student in students:
if student[2] == "IS4010": # Magic number - what does index 2 mean?
is4010_students.append(student)
# Calculate average grade (also slow)
total = 0
count = 0
for student in is4010_students:
total += student[3] # Another magic number!
count += 1
average = total / count if count > 0 else 0
return is4010_students, average
# Call the function
students, avg = process_student_data()
print(f"IS4010 students: {len(students)}, Average: {avg:.1f}")AI review prompt: “Analyze this Python code and suggest improvements for data structure choice, readability, and performance. Focus on eliminating magic numbers and handling duplicate data.”
Refactored solution
# Revised code after reviewing the suggestions
from collections import defaultdict
def process_student_data_improved():
# Better data structure: list of dictionaries
raw_students = [{"name": "Alice Johnson", "email": "alice@uc.edu", "course": "IS4010", "grade": 95},
{"name": "Bob Smith", "email": "bob@uc.edu", "course": "IS4010", "grade": 87},
{"name": "Alice Johnson", "email": "alice@uc.edu", "course": "CS2071", "grade": 92},
{"name": "Carol Davis", "email": "carol@uc.edu", "course": "IS4010", "grade": 78},
{"name": "Bob Smith", "email": "bob@uc.edu", "course": "MATH2045", "grade": 85},
]
# Group students by course (using defaultdict - AI suggestion!)
students_by_course = defaultdict(list)
unique_enrollments = set() # Handle duplicates with sets!
for student in raw_students:
# Create unique key for duplicate detection
key = (student["name"], student["email"], student["course"])
if key not in unique_enrollments:
unique_enrollments.add(key)
students_by_course[student["course"]].append(student)
# Calculate statistics for IS4010
is4010_students = students_by_course["IS4010"]
average_grade = sum(s["grade"] for s in is4010_students) / len(is4010_students)
return is4010_students, average_grade
# Much cleaner!
students, avg = process_student_data_improved()
print(f"IS4010 students: {len(students)}, Average: {avg:.1f}")What changed: - Clearer records: Dictionaries replace positional indices - Duplicate handling: A set tracks unique enrollments - Grouping: defaultdict collects records by course - Readable code: Field and variable names state their purpose
Your turn: dictionary mastery
Practice the dictionary concepts with these hands-on exercises:
# TODO: Create a product inventory dictionary
# Include: product_id, name, price, stock_quantity, category
inventory = {
"LAPTOP001": {"name": "Gaming Laptop", "price": 1299.99, "stock": 15, "category": "Electronics"},
"PHONE001": {"name": "Smartphone", "price": 699.99, "stock": 0, "category": "Electronics"},
"BOOK001": {"name": "Python Programming", "price": 39.99, "stock": 25, "category": "Books"}
}
# TODO: Practice safe access - get the price of "LAPTOP001"
try:
inventory["LAPTOP001"]["type"]
except KeyError:
print("KeyError handled gracefully")
# TODO: Check if "PHONE001" is in stock (stock_quantity > 0)
is_in_stock = inventory.get("PHONE001", {}).get("stock", 0) > 0
print(f"Is PHONE001 in stock? {'Yes' if is_in_stock else 'No'}")
# TODO: Add a new product using setdefault
inventory.setdefault("TABLET001", {"name": "Tablet", "price": 499.99, "stock": 30, "category": "Electronics"})
# Add to dict using []
inventory["HEADPHONES001"] = {"name": "Wireless Headphones", "price": 199.99, "stock": 50, "category": "Electronics"}
# TODO: Create a dictionary comprehension to get all product names
product_names = {pid: details["name"] for pid, details in inventory.items()}
print(f"Product names: {product_names}")
# DO the same using a list comprehension
product_names_list = [details["name"] for details in inventory.values()]
# Now use a for loop to print each product name
for name in inventory.values():
print(name["name"])
# TODO: Filter to get only products with stock > 10
# TODO: Use .pop() to remove PHONE001 and print what was removed
inventory.pop("PHONE001", None) # Remove PHONE001 if it existsThe set: unique items only
- A set is an unordered collection of unique items
- No duplicates allowed: Automatically removes duplicate entries
- Lightning fast membership testing:
item in setis extremely efficient - Mathematical operations: Union, intersection, difference operations
- Syntax: Items in curly braces
{}or useset()constructor - Mutable: Add and remove items after creation
- Use cases: Remove duplicates, track unique visitors, mathematical set operations
# Website analytics: tracking unique visitors
daily_visitors = ["alice", "bob", "charlie", "alice", "david", "alice", "eve"]
monthly_visitors = ["alice", "frank", "george", "bob", "helen"]
# Remove duplicates and get unique visitors
unique_daily = set(daily_visitors)
unique_monthly = set(monthly_visitors)
print(f"Unique daily visitors: {len(unique_daily)}") # 5 unique visitors
print(f"Daily visitors: {unique_daily}")
# Set operations (mathematical set theory)
all_visitors = unique_daily | unique_monthly # Union: all unique visitors
returning_visitors = unique_daily & unique_monthly # Intersection: visitors in both
new_visitors = unique_monthly - unique_daily # Difference: monthly-only visitors
print(f"All unique visitors: {all_visitors}")
print(f"Returning visitors: {returning_visitors}")
print(f"New visitors this month: {new_visitors}")
# Adding and removing items
unique_daily.add("ivan") # Add new visitor
unique_daily.discard("bob") # Remove visitor (safe - no error if not found)
# Create set from list to remove duplicates
languages = ["Python", "Java", "Python", "C++", "Java", "Rust"]
unique_languages = set(languages)
print(f"Unique programming languages: {unique_languages}")
# Fast membership testing
if "Python" in unique_languages:
print("Python is one of our tracked languages")Live exercise: choose structures for API data
Scenario: Design structures for the stated dashboard queries, then explain the trade-offs.
# Realistic API response from student management system
api_response = {
"students": [{
"id": 12345,
"username": "alice_j",
"profile": {
"name": "Alice Johnson",
"email": "alice@uc.edu",
"year": "junior",
"major": "Information Systems"
},
"courses": [{"code": "IS4010", "grade": 95, "credits": 3},
{"code": "CS2071", "grade": 88, "credits": 4},
{"code": "MATH2045", "grade": 92, "credits": 3}
],
"activities": ["ACM", "IS Club", "Dean's List"],
"permissions": ["student", "tutor", "lab_assistant"]
},
{
"id": 67890,
"username": "bob_s",
"profile": {
"name": "Bob Smith",
"email": "bob@uc.edu",
"year": "senior",
"major": "Computer Science"
},
"courses": [{"code": "IS4010", "grade": 87, "credits": 3},
{"code": "CS5168", "grade": 91, "credits": 3}
],
"activities": ["IEEE", "Hackathon Club"],
"permissions": ["student", "teaching_assistant"]
}
],
"metadata": {
"total_students": 2,
"timestamp": "2024-03-15T10:30:00Z",
"api_version": "v2.1"
}
}AI design prompt: “I need to design data structures for a student dashboard with these requirements: 1. Fast lookup of students by username 2. Quick filtering by course enrollment 3. Efficient permission checking 4. Find students with specific activities What data structures should I use and why?”
Your turn: set mastery
Apply set operations to solve real-world problems:
# TODO: Social media platform analysis
instagram_followers = {"alice", "bob", "charlie", "diana", "eve", "frank"}
twitter_followers = {"bob", "diana", "grace", "henry", "ivan", "frank"}
tiktok_followers = {"alice", "charlie", "grace", "jane", "diana"}
# TODO: Find followers who follow you on ALL platforms
all_platforms = instagram_followers & twitter_followers & tiktok_followers
# TODO: Find your total unique audience across all platforms
total_audience = instagram_followers | twitter_followers | tiktok_followers
# Do the same using set.union()
total_audience_union = set().union(instagram_followers, twitter_followers, tiktok_followers)
# TODO: Find followers who are ONLY on Instagram
instagram_only = instagram_followers - (twitter_followers | tiktok_followers)
# TODO: Find followers who are on Instagram OR Twitter, but not both
instagram_twitter_xor = instagram_followers ^ twitter_followers
# TODO: Use set comprehension to create tags from a blog post
blog_post = "Python programming data science machine learning AI artificial intelligence"
tags = {word.lower() for word in blog_post.split()}
# TODO: Check if required skills are a subset of candidate skills
required_job_skills = {"python", "sql", "excel"}
candidate_skills = {"python", "sql", "excel", "tableau", "r"}
# TODO: Find what additional skills the candidate bringsData structures for common queries
# Build structures that support the required queries
def process_student_api_data(api_response):
students_data = api_response["students"]
# 1. Fast username lookup - Dictionary
students_by_username = {}
# 2. Course enrollment tracking - Dictionary of sets
students_by_course = {}
# 3. Activity membership - Dictionary of sets
students_by_activity = {}
# 4. Permission checking - Dictionary of sets
students_by_permission = {}
# Process each student into the query structures
for student in students_data:
username = student["username"]
students_by_username[username] = student
# Index by courses
for course in student["courses"]:
course_code = course["code"]
if course_code not in students_by_course:
students_by_course[course_code] = set()
students_by_course[course_code].add(username)
# Index by activities
for activity in student["activities"]:
if activity not in students_by_activity:
students_by_activity[activity] = set()
students_by_activity[activity].add(username)
# Index by permissions
for permission in student["permissions"]:
if permission not in students_by_permission:
students_by_permission[permission] = set()
students_by_permission[permission].add(username)
return {
"by_username": students_by_username,
"by_course": students_by_course,
"by_activity": students_by_activity,
"by_permission": students_by_permission
}
# Build the optimized structures
optimized_data = process_student_api_data(api_response)
# These structures avoid repeated full-list scans
print(f"Students in IS4010: {optimized_data['by_course']['IS4010']}")
print(f"ACM members: {optimized_data['by_activity']['ACM']}")
print(f"Teaching assistants: {optimized_data['by_permission']['teaching_assistant']}")
# Complex query: IS4010 students who are also ACM members
is4010_students = optimized_data['by_course']['IS4010']
acm_members = optimized_data['by_activity']['ACM']
is4010_acm = is4010_students & acm_members # Set intersection!
print(f"IS4010 + ACM: {is4010_acm}")Check the result: - O(1) lookups instead of O(n) searches - Set operations for complex filtering - Multiple access patterns supported efficiently - Memory trade-off for speed (typical AI recommendation)
Choosing the right data structure
- Use a
listwhen you need an ordered, changeable collection- Shopping carts, todo items, search results, user feeds
- Use a
tuplewhen you need ordered, unchangeable data- Coordinates, RGB colors, database records, configuration settings
- Use a
dictwhen you need fast key-based lookups- User profiles, settings, caches, JSON data, databases
- Use a
setwhen you need unique items and fast membership testing- Unique visitors, tags, permissions, removing duplicates
# Real-world decision making examples
# E-commerce shopping cart (order matters, items change)
shopping_cart = ["laptop", "mouse", "keyboard", "monitor"]
# Product coordinates (fixed position data)
warehouse_location = (39.1031, -84.5120, 1) # lat, lon, floor
# User account information (key-value lookups)
user_account = {
"user_id": 12345,
"email": "student@uc.edu",
"subscription": "premium",
"last_login": "2024-03-15"
}
# User permissions (unique items, fast checking)
user_permissions = {"read", "write", "delete", "admin"}
# Decision logic in action
def can_user_edit(user_permissions, required_permission):
"""Check if user has required permission - O(1) lookup!"""
return required_permission in user_permissions
# Performance comparison
import time
# Checking membership in list vs set
large_list = list(range(10000))
large_set = set(range(10000))
# This is slow for lists (O(n))
# result = 9999 in large_list
# This is fast for sets (O(1))
# result = 9999 in large_setInteractive challenge: data-structure choices
Work with an AI assistant for 15 minutes, then verify its recommendation against each requirement.
Challenge 2: e-commerce inventory
# Product inventory system
inventory = [{"sku": "LAP001", "name": "Laptop", "price": 999, "categories": ["electronics", "computers"], "stock": 5},
{"sku": "MOU002", "name": "Mouse", "price": 25, "categories": ["electronics", "accessories"], "stock": 50},
{"sku": "KEY003", "name": "Keyboard", "price": 75, "categories": ["electronics", "accessories"], "stock": 30},
]
# Goals: Fast product lookup, category filtering, inventory alerts
# Ask your AI: "How do I optimize product search and filtering?"Challenge 3: university course scheduler
# Course scheduling conflicts
courses = [{"code": "IS4010", "time": "MWF 10:00", "room": "Lindner 100", "students": ["alice", "bob"]},
{"code": "CS2071", "time": "TTh 14:00", "room": "Lindner 200", "students": ["alice", "carol"]},
{"code": "MATH2045", "time": "MWF 10:00", "room": "Swift 300", "students": ["bob", "dave"]},
]
# Goals: Detect time conflicts, room utilization, student schedules
# Ask your AI: "What's the best way to handle scheduling conflicts?"Your task: 1. Pick ONE challenge that interests you most 2. Consult an AI assistant for data structure recommendations 3. Be ready to share your AI’s best suggestion with the class 4. Bonus: Implement a quick prototype if you’re feeling ambitious!
Challenge solution discussion
Compare the recommendations with the requirements and trade-offs.
E-commerce inventory: expected approaches
- Product lookup: Dictionary with SKU as key for O(1) access
- Category filtering: Dictionary mapping categories to product sets
- Inventory alerts: Separate low-stock tracking with threshold checking
- Price queries: Sorted structures or separate indexing for range queries
Course scheduling: expected approaches
- Time conflict detection: Dictionary grouping courses by time slots
- Room utilization: Dictionary tracking room→courses mapping
- Student schedules: Dictionary with student→courses for individual schedules
- Conflict resolution: Set operations for finding overlapping students/times
Key AI Insights: - Candidate generation: Ask an assistant for more than one representation - Trade-off analysis: Require a cost and benefit for each candidate - Measurement: Benchmark the operation before accepting a performance claim - Edge cases: Test duplicates, missing values, empty inputs, and ordering
Putting it all together: Lab 04
Lab 04 asks you to implement three functions in week04/lab04.py:
find_common_elements(list1, list2)returns values found in both listsfind_user_by_name(users, name)returns a matching user dictionary orNoneget_list_of_even_numbers(numbers)retains even integers in their original order- Empty inputs, zero, and negative even numbers must behave as specified
- The supplied tests must not be modified
Workflow:
uv run --directory week04 python -m pytest tests/ -v
git add week04/lab04.py
git commit -m "Complete Lab 04"
git pushInstructions: week04/lab04.md
Social media analytics: expected approaches