๐Ÿ” TypeVar, Generic, Protocol (structural subtyping)WORKSHOP
1
2
3
4
5

Step 1

Define `T = TypeVar('T')` and write two generic functions: `identity(x: T) -> T` that returns its argument unchanged, and `first(items: list[T]) -> T` that returns the first element. Both should be typed so that the return type matches the input type โ€” not `Any`.

โŒ˜ Enter (Mac) ยท Ctrl+Enter (Win/Linux)