Is it possible to emulate something like sum() using list comprehension ?
For example - I need to calculate the product of all elements in a list :
list = [1, 2, 3]
product = [magic_here for i in list]
#product is expected to be 6
Code that is doing the same :
def product_of(input):
result = 1
for i in input:
result *= i
return result
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…