I'm making a function where I have to find a the lowest value in a list of lists recursively. For example, a list containing [1, 2, 3, [4, 5]] would return 1.
I have some code written already. However, I don't know how to iterate through a list and compare the lowest number to a list.
I have included a comment where my function gets an error in my code below: def recMin(nestedLis):
lowest = 1000000
if len(nestedLis) < 2:
return nestedLis
else:
# This function works until it hits a list in a list (ex. [1, 2])
# because it cannot compare a list to an int. I don't know how to fix this
if nestedLis[0] < lowest:
lowest = nestedLis[0]
print(lowest)
return lowest + recMin(nestedLis[1:])
Any help would be greatly appreciated!