Complete the code to map the task over the list of numbers.
from airflow.decorators import task @task def square_number(number): return number [1] 2 results = square_number.expand(number=[1, 2, 3, 4])
The ** operator is used to raise a number to a power. Here, it squares the number.
Complete the code to define a mapped task that prints each item.
from airflow.decorators import task @task def print_item(item): print(item) print_item.expand(item=[1])
The expand method expects an iterable. A list of strings is a good example.
Fix the error in the mapped task call to correctly map over the list.
from airflow.decorators import task @task def multiply_by_two(x): return x * 2 results = multiply_by_two.expand(x=[1])
The expand method requires an iterable like a list to map the task over multiple inputs.
Fill both blanks to create a mapped task that filters even numbers and squares them.
from airflow.decorators import task @task def process_number(n): if n [1] 2 == 0: return n[2]2 results = process_number.expand(n=[1, 2, 3, 4, 5])
The modulo operator % checks if a number is even. The power operator ** squares the number.
Fill all three blanks to create a mapped task that returns a dictionary with uppercase keys and values greater than zero.
from airflow.decorators import task @task def filter_and_transform(data): return { [1]: [2] for [3], v in data.items() if v > 0 } results = filter_and_transform.expand(data=[{'a': 1, 'b': -1}, {'c': 3, 'd': 0}])
The dictionary comprehension uses k.upper() for keys, v for values, and k as the key variable in the loop.