Skip to content
Foxipa
Code Completion 4 Challenges

Complete the Python generic type parameters code

Practice generic functions, classes, type aliases, and multiple type parameters.

Advanced ~9 min read

Challenge 1

Make first generic over an element type T.

python Your answer


print(first([10, 20, 30]))

Press Ctrl⌘Enter to check your answer

Challenge 2

Make Box generic over the type of value it stores.

python Your answer


box = Box(42)
print(box.value)

Press Ctrl⌘Enter to check your answer

Challenge 3

Create the generic Pair alias used by the annotation.

python Your answer


point: Pair[int] = (3, 4)
print(point)

Press Ctrl⌘Enter to check your answer

Challenge 4

Make pair generic over two different types, T and U.

python Your answer


print(pair(7, "seven"))

Press Ctrl⌘Enter to check your answer