I want to take in a list with nested lists. Then print the highest value of index 0 or 2 in the list and the lowest value of index 0 or 2, through using recursion.
This is what I got so far:
lst = [1, 5, [7, 10, []]]
def high_low(my_list):
new_lst = []
if not my_list:
print max(new_lst)
print min(new_lst)
elif isinstance(my_list[0], int):
return new_lst.append(my_list[0]) + high_low(my_list[2:])
elif isinstance(my_list[0], list):
return new_lst.append(max(my_list[0])) + high_low(my_list[2:])
This is where I get stuck, as I don't know how to get the highest and lowest value from a nested list and then append it to the new empty list. For example this is what I want the output to look like:
>>> print_tree(lst)
10
1