Python Data Structures Workshop
Duration: 3 Hours
Topics: List, Tuple, Set, Dictionary
Method: Quick theory + Syntax demo + Hands-on problems
Hour 1: Lists (50 mins)
• Definition: Ordered, mutable, allows duplicates
• Syntax: my_list = [1, 2, 3, 4]
• Common operations: append(), insert(), remove(), pop(), slicing, indexing
• Problems:
• 1. Create a list of 5 numbers and print the sum
• 2. Access the last 3 elements of a list
• 3. Add 'Python' to a list of programming languages
• 4. Remove duplicates from a list
• 5. Reverse a list without using reverse() or slicing
• 6. Find the largest and smallest element
• 7. Count how many times 'apple' appears in a list
Hour 2: Tuples (25 mins)
• Definition: Immutable, ordered, faster than lists
• Syntax: my_tuple = (1, 2, 3)
• Problems:
• 1. Create a tuple of 5 names and print them one by one
• 2. Convert a tuple into a list, add a new element, and convert back
• 3. Find the index of a given element in a tuple
• 4. Check if 'Python' exists in a tuple
Hour 2: Sets (25 mins)
• Definition: Unordered, no duplicates, mutable
• Syntax: my_set = {1, 2, 3}
• Problems:
• 1. Create a set of numbers from 1–5. Add and remove elements
• 2. Show union, intersection, difference of two sets
• 3. Remove duplicates from a list using a set
• 4. Check if a set is subset/superset of another
• 5. Find common elements between two sets
Hour 3: Dictionaries (50 mins)
• Definition: Key-value pairs, unordered, mutable
• Syntax: my_dict = {'name': 'Alice', 'age': 25}
• Problems:
• 1. Create a dictionary with student names as keys and marks as values
• 2. Access the value of a specific key
• 3. Add a new key-value pair
• 4. Update an existing value
• 5. Delete a key from the dictionary
• 6. Loop through keys and values
• 7. Create a word frequency counter
• 8. Merge two dictionaries
• 9. Find the student with the highest marks
Final 10 mins
• Quick recap & Q/A
• Small quiz:
• - Which data structure allows duplicates but is immutable?
• - Which is faster for lookups: list or dictionary?
• - Write code to find common items between two lists using sets