Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
370 B
2
Indexable
Never
def sum_nested_lists(nested_list):
    total = 0
    for element in nested_list:
        if isinstance(element, list):
            total += sum_nested_lists(element)
        else:
            total += element
    return total

# Example usage:
nested_list = [[1, 2, 3], [4, 5], [6, [7, 8], 9]]
result = sum_nested_lists(nested_list)
print("Sum of nested lists:", result)
Leave a Comment