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
It is possible to achieve by using lambda with list comprehension Since we can't assign a value in list comprehension we go with lambda
Solution:
>>> (lambda number_list, sum=0:[sum for number in number_list for sum in [sum + number]][-1])([1, 2, 3, 4, 5]) >>> 15