Cody Bable

Generation

generate functionFri, 30 Jun 2023

return list dictionary of the two biggest numbers in a list of dictionaries

def the_two_biggest_numbers(num_list): biggest = 0 second_biggest = 0 first_biggest_dict = {} second_biggest_dict = {} for i in num_list: if i["number"] > biggest: second_biggest = biggest first_biggest_dict = i biggest = i["number"] elif i["number"] > second_biggest: second_biggest_dict = i second_biggest = i["number"] return [first_biggest_dict, second_biggest_dict] the_two_biggest_numbers([{"number": 1}, {"number": 2}, {"number": 3}, {"number": 4}])

Questions about programming?Chat with your personal AI assistant