Martin McBride
Jul 27, 2023

Your reduce example is the best way to do this, but there is no need to use a lambda for the multiply functions. You can use the mul function from the operator module:

```

def f(lis):

return reduce(mul, lis)

```

I'm not a huge fan of one liners for the sake of it, but this code is using reduce and mul exactly as intended and it just happens to only take one line.

Martin McBride
Martin McBride

No responses yet