compose(f, g) returning a new function equivalent to f(g(x)). Then use it to build clean = compose(str.strip, str.lower)... wait — order matters: compose(str.strip, str.lower) lowercases first, then strips. Your returned function must accept a single argument.compose(lambda x: x + 1, lambda x: x * 2)(5)
11
g doubles 5 to 10, then f adds 1.
compose(str.strip, str.lower)(' HeLLo ')'hello'
Lowercased first, then stripped.
Return lambda x: f(g(x)).
Closures capture f and g automatically.