Lesson 10
Lesson 10 of 34
List processing
Lesson Progress: 0%
Code Example
# Example 1
fruits = ["apple", "banana"]
fruits.append("cherry")
# Example 2
numbers = [1, 2, 3]
numbers.append(4)Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
append() helper.fruits.append("cherry") puts a cherry at the very end of your fruit list.Code Example
# Example 1
colors = ["red", "blue"]
more_colors = ["green", "yellow"]
colors.extend(more_colors)
# Example 2
points = [10, 20]
points.extend([30, 40])Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
extend() that lets you pour one list into another.Code Example
# Example 1
names = ["Alice", "Charlie"]
names.insert(1, "Bob") # Puts "Bob" at index 1
# Example 2
queue = [2, 3, 4]
queue.insert(0, 1) # Puts 1 at the very startInstructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
append() always goes to the end, insert() lets you pick any spot in your list.Code Example
# Example 1
pets = ["cat", "dog", "bird"]
pets.remove("dog")
# Example 2
scores = [10, 50, 100]
scores.remove(50)Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
remove().Code Example
# Example 1
letters = ["a", "b", "c"]
last_item = letters.pop() # Removes "c"
# Example 2
tasks = ["clean", "cook", "sleep"]
first_task = tasks.pop(0) # Removes "clean"Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
pop() helper is like a "grabber" that takes an item out of your list so you can use it.Code Example
# Example 1
prices = [5.0, 1.0, 3.5]
prices.sort()
# Example 2
kids = ["Zane", "Abby", "Mark"]
kids.sort()Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
pop() helper is like a "grabber" that takes an item out of your list so you can use it.Code Example
# Example 1
countdown = [1, 2, 3]
countdown.reverse() # Becomes [3, 2, 1]
# Example 2
words = ["world", "hello"]
words.reverse() # Becomes ["hello", "world"]Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
pop() helper is like a "grabber" that takes an item out of your list so you can use it.Code Example
# Example 1
players = ["Sam", "Jan", "Kit"]
total = len(players) # total is 3
# Example 2
items = [10, 20, 30, 40, 50]
count = len(items) # count is 5Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
pop() helper is like a "grabber" that takes an item out of your list so you can use it.Code Example
# Example 1: Everyone finished the race
finished = [True, True, True]
result = all(finished) # result is True
print(result)
# Example 2: One person forgot their shoes
has_shoes = [True, False, True]
result = all(has_shoes) # result is False
print(result)
# Example 3: Checking if all numbers are non-zero
numbers = [1, 5, 10]
result = all(numbers) # result is True
print(result)Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
pop() helper is like a "grabber" that takes an item out of your list so you can use it.Code Example
# Example 1: Someone found the hidden key
found_key = [False, True, False]
result = any(found_key) # result is True
print(result)
# Example 2: Nobody is awake
is_awake = [False, False, False]
result = any(is_awake) # result is False
print(result)
# Example 3: At least one person has a snack
has_snack = [False, False, True]
result = any(has_snack) # result is True
print(result)Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
pop() helper is like a "grabber" that takes an item out of your list so you can use it.Code Example
# Check if all numbers are greater than 2
numbers = [3, 5, 10]
result = all(n > 2 for n in numbers)
print(result)
)
# Check if all words have at least 3 letters
words = ["cat", "dog", "bear"]
result = all(len(w) >= 3 for w in words)
print(result) # This will be True
# Check if all words have at least 3 letters
users = [{"name": "David","active": True},
{"name": "Mike","active": True}]
result = all(user["active"] for user in users)
print(result)Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
pop() helper is like a "grabber" that takes an item out of your list so you can use it.