Module 3
>Data Structures
Organize many values with lists, tuples, strings, sets, dictionaries, and comprehensions.
// Lessons
5
// Quiz questions
50
// Reading time
60 min
// Exam length
15 Q
// Coding exercises
9
- 1Python ListsCreate, read, change, sort, and safely copy lists of values. 12 min 10 questions
- 2TuplesStore fixed values in tuples and unpack them into useful names. 10 min 10 questions
- 3Working with StringsRead, combine, search, clean, and loop through text with strings. 12 min 10 questions
- 4Sets and DictionariesUse sets for unique values and dictionaries for named values. 14 min 10 questions
- 5ComprehensionsBuild lists, sets, and dictionaries quickly from iterable values. 12 min 10 questions
Coding practice: write it yourself
Real Python, real checks: write your answer, press Run checks, and keep going until it passes. (0/4 passed this visit)
You can run every exercise now. Create a free ID to keep passes, code attempts and XP.
Lab 1: Shopping basket
Not passed yetStarting from ["rice", "oil"], append "dates", then print the whole list followed by its length on one line — like ['rice', 'oil', 'dates'] 3.
basket = ["rice", "oil"] # append dates, then print list and length
Lab 2: Top score
Not passed yetCricket scores: [88, 101, 45]. Print the highest score without sorting the list manually — there is a built-in for that.
scores = [88, 101, 45] # print the highest
Lab 3: Unique visitors
Not passed yetThe log ["Mim", "Rafi", "Mim"] has repeats. Print how many UNIQUE visitors there are.
log = ["Mim", "Rafi", "Mim"] # count unique names
Lab 4: Safe marks lookup
Not passed yetWith marks = {"Mim": 78}, print Mim's marks AND Rafi's using .get() with default 0 — expecting 78 0.
marks = {"Mim": 78}
# print both lookups safely
References & Further Reading
Related entries from PyLabs's own reference library.