You seem to have forgotten to put the index:
def Max(s): if len(s) == 1: return s[0] else: m = Max(s[1:]) if m > s[0]:
m is a single number, so it cannot be compared with s , which is list . So you got your error.
Side note, consider using the triple operation [true_val if true_cond else false_val] to simplify your notation. Also, you do not need the last else block, since your if clause has a specific return before leaving the block:
def Max(s): if len(s) == 1: return s[0] m = Max(s[1:]) return m if m > s[0] else s[0]
Then your code will become much easier.
source share