0 out of 464 challenges solved

Flatten and Sum List

Write a Python function `recursive_list_sum(data_list)` that takes a nested list of integers as input and returns the sum of all its elements. The function should handle lists that contain other lists (nested lists) and sum all the integers within them.

#### Example Usage
```python [main.nopy]
print(recursive_list_sum([1, 2, [3, 4], [5, 6]]))  # Output: 21
print(recursive_list_sum([7, 10, [15, 14], [19, 41]]))  # Output: 106
print(recursive_list_sum([10, 20, [30, 40], [50, 60]]))  # Output: 210
```

#### Constraints
- The input list will only contain integers or other lists.
- The function should handle arbitrarily nested lists.
def recursive_list_sum(data_list):
    """
    Recursively sums all integers in a nested list.

    Args:
        data_list (list): A list containing integers or other lists.

    Returns:
        int: The sum of all integers in the nested list.
    """
    # Initialize the total sum
    total = 0
    # Iterate through each element in the list
    for element in data_list:
        # Check if the element is a list
        if isinstance(element, list):
            # Recursively sum the nested list
            total += recursive_list_sum(element)
        else:
            # Add the integer to the total
            total += element
    return total