Complete the code to define an async route handler in FastAPI.
from fastapi import FastAPI app = FastAPI() @app.get("/items") async def get_items(): return {"message": "Hello from [1] function!"}
The route handler must be declared with async to enable asynchronous behavior in FastAPI.
Complete the code to await an async operation inside the route handler.
import asyncio from fastapi import FastAPI app = FastAPI() @app.get("/wait") async def wait_seconds(): await [1](1) return {"message": "Waited 1 second"}
Use await asyncio.sleep(1) to pause asynchronously without blocking the event loop.
Fix the syntax error in the route handler by completing the code correctly.
from fastapi import FastAPI app = FastAPI() @app.get("/data") def [1](): return {"data": "sync function"}
To fix the syntax error, fill the function name get_data in the blank. The def and function name must be on the same line. Adding async def in the blank would cause a syntax error.
Fill both blanks to create a dictionary comprehension that filters async tasks with duration greater than 2.
tasks = {task: duration for task, duration in durations.items() if duration [1] 2 and task.startswith([2])}The comprehension filters tasks with duration greater than 2 and task names starting with "a".
Fill all three blanks to create a dictionary comprehension that maps uppercase task names to durations for tasks longer than 3 seconds.
result = [1]: [2] for [3], duration in durations.items() if duration > 3
The comprehension maps uppercase task names (task.upper()) to their durations for tasks longer than 3 seconds.