Lesson 10 of 34
Lesson Progress: 0%
fruits = ["apple", "banana"]
fruits.append("cherry")
print(fruits)
numbers = [1, 2, 3]
numbers.append(4)
print(numbers)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.colors = ["red", "blue"]
more_colors = ["green", "yellow"]
colors.extend(more_colors)
print(colors)
points = [10, 20]
points.extend([30, 40])
print(points)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.names = ["Alice", "Charlie"]
names.insert(1, "Bob") # Puts "Bob" at index 1
print(names)
queue = [2, 3, 4]
queue.insert(0, 1) # Puts 1 at the very start
print(queue)Instructions
▼ ← 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.pets = ["cat", "dog", "bird"]
pets.remove("dog")
print(pets)
scores = [10, 50, 100]
scores.remove(50)
print(scores)Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
remove().letters = ["a", "b", "c"]
last_item = letters.pop() # Removes "c"
print(letters)
print(last_item)
tasks = ["clean", "cook", "sleep"]
first_task = tasks.pop(0) # Removes "clean"
print(tasks)
print(first_task)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.prices = [5.0, 1.0, 3.5]
prices.sort()
print(prices)
kids = ["Zane", "Abby", "Mark"]
kids.sort()
print(kids)Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
sort() function helps put items in order in a list.countdown = [1, 2, 3]
countdown.reverse()
print(countdown)
words = ["world", "hello"]
words.reverse()
print(words)Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
reverse() function flips the order of items in a list.players = ["Sam", "Jan", "Kit"]
total = len(players)
print(total)
items = [10, 20, 30, 40, 50]
count = len(items)
print(count)Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
len() function tells you how many items are in a list.# Everyone finished the race
finished = [True, True, True]
result = all(finished) # result is True
print(result)
# One person forgot their shoes
has_shoes = [True, False, True]
result = all(has_shoes) # result is False
print(result)
# 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:
all() function checks if every item in a list is true.True, but if even one is false, it returns False.# Someone found the hidden key
found_key = [False, True, False]
result = any(found_key) # result is True
print(result)
# Nobody is awake
is_awake = [False, False, False]
result = any(is_awake) # result is False
print(result)
# 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:
any() function checks if at least one item in a list is true.True, otherwise it returns False.# 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:
all() function can check rules, not just simple true or false values.(n > 2 for n in numbers) checks each number to see if it is bigger than 2.(len(w) >= 3 for w in words) checks if each word has at least 3 letters.(user["active"] for user in users) checks if each user is active.all() to return True.# Check if any number is greater than 10
numbers = [3, 5, 12]
result = any(n > 10 for n in numbers)
print(result) # This will be True
# Check if any word has at least 5 letters
words = ["cat", "dog", "elephant"]
result = any(len(w) >= 5 for w in words)
print(result) # This will be True
# Check if any user is active
users = [
{"name": "David", "active": False},
{"name": "Mike", "active": True}
]
result = any(user["active"] for user in users)
print(result) # This will be TrueInstructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
any() function checks if at least one item in a list meets a condition.any() a rule to check, like n > 10.(n > 10 for n in numbers) checks each number to see if it is greater than 10.(len(w) >= 5 for w in words) checks if any word has 5 or more letters.(user["active"] for user in users) checks if any user is active.any() will return True.Test Incomplete