Practice ยท 1 of 1
A generic Stack[T]
Implement Stack(Generic[T]) with push(item: T), pop() -> T (IndexError on empty), peek() -> T (IndexError on empty), and __len__. Also implement first(xs: List[T]) -> T raising ValueError('empty sequence') on an empty list.
Runtime must behave exactly like the untyped version โ the generic parameter is a design contract (your annotations must reference T where relevant).
Difficulty: advanced
Press Submit to check your solution.
Back to lesson: Practice: Generics Practice