0
0
FastAPIframework~10 mins

List and set validation in FastAPI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the correct Pydantic type for a list of strings.

FastAPI
from pydantic import BaseModel, [1]

class Item(BaseModel):
    tags: [1][str]
Drag options to blanks, or click blank then click option'
AList
BTuple
CDict
DSet
Attempts:
3 left
💡 Hint
Common Mistakes
Using Set instead of List when order matters.
Forgetting to import the type from Pydantic.
2fill in blank
medium

Complete the code to import the correct Pydantic type for a set of integers.

FastAPI
from pydantic import BaseModel, [1]

class Numbers(BaseModel):
    unique_ids: [1][int]
Drag options to blanks, or click blank then click option'
ASet
BList
CDict
DTuple
Attempts:
3 left
💡 Hint
Common Mistakes
Using List when uniqueness is required.
Confusing Set with Dict.
3fill in blank
hard

Fix the error in the code to correctly validate a list of strings using Pydantic.

FastAPI
from pydantic import BaseModel, [1]

class User(BaseModel):
    hobbies: [1][str]
Drag options to blanks, or click blank then click option'
ASet
BDict
CList
DTuple
Attempts:
3 left
💡 Hint
Common Mistakes
Using Set which does not preserve order.
Using Dict which expects key-value pairs.
4fill in blank
hard

Fill both blanks to define a Pydantic model with a list of strings and a set of integers.

FastAPI
from pydantic import BaseModel, [1], [2]

class Data(BaseModel):
    names: [1][str]
    ids: [2][int]
Drag options to blanks, or click blank then click option'
AList
BSet
CDict
DTuple
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up List and Set types.
Forgetting to import both types.
5fill in blank
hard

Fill all three blanks to create a Pydantic model with a list of strings, a set of integers, and a tuple of floats.

FastAPI
from pydantic import BaseModel, [1], [2], [3]

class Metrics(BaseModel):
    labels: [1][str]
    unique_codes: [2][int]
    scores: [3][float]
Drag options to blanks, or click blank then click option'
AList
BSet
CTuple
DDict
Attempts:
3 left
💡 Hint
Common Mistakes
Using Dict instead of Tuple for fixed-length sequences.
Not importing all required types.