Practice module 3
>Data Structures: coding practice
Start with the lesson drills, then combine the ideas in the module labs. Every task has automatic checks, progressive hints, reset and a solution.
Lesson coding drills
One focused editor exercise for every lesson in this module. (0/5 passed this visit)
You can run every exercise now. Create a free ID to keep passes, code attempts and XP.
Lesson 1: Python Lists
Not passed yetCreate numbers = [4, 1, 3]. Append 2, sort the list in place, then print it.
Expected output: [1, 2, 3, 4]
# Write your code below
Lesson 2: Tuples
Not passed yetMake a tuple city = ('Paris', 'France'). Unpack it into name and country, then print name.
Expected output: Paris
# Write your code below
Lesson 3: Working with Strings
Not passed yetSet text = ' red,blue '. Remove surrounding spaces, split on the comma, then join the colors with ' | ' and print the result.
Expected output: red | blue
# Write your code below
Lesson 4: Sets and Dictionaries
Not passed yetCreate fruit = {'apple': 3, 'pear': 2}. Add 'banana' with value 5, then print fruit['banana'].
Expected output: 5
# Write your code below
Lesson 5: Comprehensions
Not passed yetUse a list comprehension to make doubled from numbers = [2, 3, 4], with every number multiplied by 2. Print doubled.
Expected output: [4, 6, 8]
# Write your code below
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.