Write a python function to add only even numbers in a list


Topic: Write a python function to add only even numbers in a list

Solution

from functools import reduce
input_list = [x for x in range(100)]
def sum_even(it):
    return reduce(lambda x, y: x + y if (y % 2)==0 else x, it, 0)
res=sum_even(input_list)
print('Sum of even numbers in the list is ', res)



List all Python Programs