I have a an element N which can be list or tuple. Element of N can be either an int, a tuple, or a list. The task is to flatten this and return the largest value.
I manage to flatten N and I am able to return a list of integer, however when I apply max() I get an error: TypeError: can only concatenate list (not "int") to list... I am not sure where I get it wrong and why, even when i try to convert the result to list:
def maxVal(n):
mode = (list,tuple)
result = sum(([x] if not isinstance(x, mode) else maxVal(x)for x in n), [])
output = []
for i in result:
output.append(i)
return max(output)
If I use return output (without the max() function) I get: [5, 1, 2, 1, 9]
thanks