Python - emulate sum() using list comprehension -


is possible emulate sum() using list comprehension ?

for example - need calculate product of elements in list :

list = [1, 2, 3] product = [magic_here in list]  #product expected 6 

code doing same :

def product_of(input):    result = 1    in input:       result *=    return result 

no; list comprehension produces list long input. need 1 of python's other functional tools (specifically reduce() in case) fold sequence single value.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -