🧭Higher-Order Function
Also known as Higher Order Function, HOF
A function that takes another function as input, or gives one back. map is one.
Think of it like
Think of it like a boss who hands a task to a helper. The boss says what; the helper does it.
Example
Emma passes str.upper to map with a list of two letters. Without writing a loop, she gets both letters in capitals.
Why it matters
They remove a lot of copy-pasted loops. One line says what to do to every item.
Definition
Example code
python
>>> list(map(str.upper, ["a", "b"]))
['A', 'B']Common mistake
Key takeaways
- 1Takes a function. Or gives one back.
- 2Reuse the loop. Swap only the action.
- 3map, filter, sort. The common ones.