List comprehensions are a concise way to create lists:
# Instead of:
squares = []
for i in range(1, 6):
squares.append(i ** 2)
# You can write:
squares = [i ** 2 for i in range(1, 6)]
print(squares) # [1, 4, 9, 16, 25]
You can also add conditions:
evens = [i for i in range(1, 11) if i % 2 == 0]
print(evens) # [2, 4, 6, 8, 10]
Use zip(bucket_list, completed) to loop through both lists together. Check the boolean to pick ✓ or ✗.
⚠️ Try solving it yourself first — you'll learn more!
# Instead of:
squares = []
for i in range(1, 6):
squares.append(i ** 2)
# You can write:
squares = [i ** 2 for i in range(1, 6)]
print(squares) # [1, 4, 9, 16, 25]