Cody Bable

Generation

generate functionFri, 30 Jun 2023

return the two biggest numbers in a list of dictionaries

def get_highest(list_of_numbers): two_biggest = [] for num in list_of_numbers: if len(two_biggest) < 2: two_biggest.append(num) else: if num >= two_biggest[0]: two_biggest[0] = num elif num >= two_biggest[1]: two_biggest[1] = num return two_biggest get_highest([1, 3, 5, 4, 2]) # [5, 4] get_highest([1, 3, 5, 4, 2, 7, 8, 10, 9]) # [10, 9]

Questions about programming?Chat with your personal AI assistant