python sum numeric values in mixed list

Solutions on MaxInterview for python sum numeric values in mixed list by the best coders in the world

showing results for - "python sum numeric values in mixed list"
Chahine
23 Mar 2016
1# Python code to add only numbers in a list of characters and numbers
2ini_list = [1, 2, 3, 4, 'a', 'b', 'x', 5, 'z']
3
4res = sum(filter(lambda i: isinstance(i, int), ini_list)) # Add numbers from list
5
6print ("Resultant sum: ", res)
7
8# Output:
9# Resultant sum: 15