Summing absolute values in a list of integers

This problem involves taking a list of integers and summing the absolute values of the integers. The example input is [1, -2, 3, -4] and the example output is 10.

Problem

Given a list of integers, return the sum of the absolute values of the integers.
Example input: [1, -2, 3, -4]
Example output: 10

Solution

This solution is in Python. Our A.I. can create solutions in multiple languages.
by elrichendelgart
def sum_abs(lst):
    return sum(map(abs, lst))

# This solution is optimal because it uses the built-in sum function, which is O(n) and the built-in map function, which is also O(n).

A.I. Evaluation of the Solution

This is a great solution! It is both complete and solves the problem optimally.

Evaluated at: 2022-11-09 02:16:06