Multiplying a subset of a list of integers together in python
python
Solution
import operator
l = [1, 2, 3, 4, 5, 6, 7, 8, 9]
print reduce(operator.mul, [v for (k, v,) in enumerate(l) if k < 5])
>> 120
Edit: Better way to do it
print reduce(operator.mul, l[:5])
>> 120
Problem
Let's say I have a list of 10 integers and I want the result of multiplying the first 5 together. Is there a pythonic way of doing this? Python seems to be great with lists :)