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
I might be a bit late for this discussion, but I would like to mention that list comprehentions are turing complete, and thus this can be done with a list comprehention!
This however is messy, so I have used the following trick, which makes a cummulative array, and returns the last element
def sum(l):
return [c[-1] for c in [[0]] for e in l if c.append(c[-1] + e) is None][-1]