Apply a Function over Argument Tuples

Hard ⏱ 18 min 25% acceptance ★★★★☆ 4.3
Write apply_all(func, arg_tuples) that calls func(*args) for every tuple in arg_tuples and returns the list of results — a hand-rolled itertools.starmap. Then demonstrate it works with a three-argument lambda.

Examples

Example 1
Input
apply_all(lambda a, b, c: a + b * c, [(1, 2, 3), (0, 5, 2)])
Output
[7, 10]
Explanation

1+2×3=7 and 0+5×2=10 — each tuple is unpacked into three parameters.

Constraints

  • Use * unpacking, not manual indexing.
  • Works for tuples of any arity that func accepts.

Topics

Lambda & Functionalargument unpacking

Companies

BloombergTwo SigmaOracle

Hints

Hint 1

func(*t) spreads the tuple into positional args.

Hint 2

A comprehension over arg_tuples finishes it.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.