In what concerns the continuous evaluation solving exercises grade during the semester, you should submit until 23:59 of December 14th
(this exercise will still be available for submission after that deadline, but without counting towards your grade)
[to understand the context of this problem, you should read the class #09 exercise sheet]
In this problem you should submit a function as described. Inside the function do not print anything that was not asked!
(in this class you are expected to write a solution that uses recursion - mooshak will not force it, but that should be your goal)
Lord Nibbler has found a peculiar dataset containing a mix of integers nested within lists and tuples. As part of his cosmic experiments, Nibbler needs to calculate the total sum of all the integers within the dataset, regardless of how deeply nested they are. However, being a creature of immense power, Nibbler doesn't want to bother with writing the solution himself. He needs your help!
Write a function sum_integers(data) that takes a single input, data, which can be a list or tuple containing integers, strings, doubles, lists, or tuples, with nested structures of arbitrary depth. It should return the sum of all the integers, regardless of how nested they were, and ignore any non-integers values.
The following limits are guaranteed in all the test cases that will be given to your program:
1 ≤ |data| ≤ 100 | length of data (when flattened) |
Example Function Calls | Example Output |
print(sum_integers([[(4,3)],(((45,[9]))),[(42)],[1,6,8]])) print(sum_integers(["a",([[2]],[["b"]]),40,[[2.2]]])) print(sum_integers((1,2,[3],[[4]]))) print(sum_integers(["hello","world"])) |
118 42 10 0 |