Python Find Max Value In List
Below code is used to find max value in list using Python.
------------------------------------------------------------------------------------------------
#Output
505
#Python find max value in list items = [5, 6, 34, 55, 43, 48, 505, 32, 54, 88, 90] def find_max(items_list): #return last item in list: breaking condition if len(items_list) == 1: return items_list[0] #Otherwise get the first item and call function #Iterate to the rest of list opt1 = items_list[0] opt2 = find_max(items_list[1:]) #Compare when done if opt1 > opt2: return opt1 else: return opt2 print(find_max(items))
------------------------------------------------------------------------------------------------
#Output
505
Comments
Post a Comment