Aug-01-2017, 07:42 AM
Hi All
New to coding/python, and still battling with a couple of concepts. Need some help with regards to a function that I'm meant to write.
So basically need this bottom function to work, but the code is not doing exactly what is expected. If anyone can point me in the right direction, or show me code to help me understand this better.
..... the output should be 9 not 5....
New to coding/python, and still battling with a couple of concepts. Need some help with regards to a function that I'm meant to write.
So basically need this bottom function to work, but the code is not doing exactly what is expected. If anyone can point me in the right direction, or show me code to help me understand this better.
..... the output should be 9 not 5....
def max_val(t): """ t, tuple or list Each element of t is either an int, a tuple, or a list No tuple or list is empty Returns the maximum int in t or (recursively) in an element of t """ maxnum = float('-inf') for x in t: if isinstance(x, (list,tuple)): max_val(x) else: if x > maxnum: maxnum = x return maxnum print(max_val((5, (1,2), [[1],[9]])))