You can get the sum of negative integers in a list by using the following code in Python:
main.py151 chars4 lines
The sum()
function is used to return the sum of all the elements in the list. We use the filter()
function to filter out the negative numbers from the list. The lambda
function is applied to each element in the list to check if it is less than zero. This will give a list of all negative numbers which will be passed to the sum function to get the sum of all the negative integers in the list.
Output:
main.py50 chars2 lines
gistlibby LogSnag