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 :
l
Found the magic on http://code.activestate.com/recipes/436482/.
>>> L=[2, 3, 4] >>> [j for j in [1] for i in L for j in [j*i]][-1] 24
It should be the logic like the following code.
L=[2, 3, 4] P=[] for j in [1]: for i in L: for j in [j*i]: P.append(j) print(P[-1])