13.product


#1

def product(num):
out = 1
for i in num:
out *= i
return out

print product([1, 4, 3])

how to make that function in one line kind like this:
(its not correct i dont kno how to do it correct)

def product(num):
return [ 1 *= x for x in num if x > 2]


#2

So far i know you can't, you cant use *=. You can multiply, but with *, not *=, list comprehension doesn't work that way.


#3

Try:

out = i * out


#5

@boyzac2, that wasn't the question, the question was how to use list comprehension to achieve this exercise. And posting full answers is not according to the guidelines


#6

Ok, sorry about that. I misinterpreted what was being asked. :worried: