Sum of positive integers in a list

This technical problem deals with finding the sum of all the positive integers in a list. If the list is empty, the function will return 0.

Problem

Given a list of integers, write a Python function to return the sum of the positive integers in the list. If the list is empty, return 0.
Input: [1, -2, 3, 4, -5]
Output: 11

Solution

This solution is in Python. Our A.I. can create solutions in multiple languages.
by kayakane
def sum_positive(lst):
    return sum(x for x in lst if x > 0)

# This solution is optimal because it uses a generator expression to filter the list and then sum the positive integers.
# This is optimal because it is a one-liner and it is also very readable.

A.I. Evaluation of the Solution

This solution is optimal because it uses a generator expression to filter the list and then sum the positive integers. This is optimal because it is a one-liner and it is also very readable.

Evaluated at: 2022-11-19 08:16:26