Cody Bable

Generation

generate functionFri, 30 Jun 2023

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

def return_biggest(list_of_dictionaries): biggest_key_1 = 0 biggest_value_1 = 0 biggest_key_2 = 0 biggest_value_2 = 0 for row in list_of_dictionaries: key = row.keys()[0] value = row.values()[0] if value > biggest_value_1: biggest_value_2 = biggest_value_1 biggest_key_2 = biggest_key_1 biggest_value_1 = value biggest_key_1 = key elif value > biggest_value_2: biggest_value_2 = value biggest_key_2 = key return {biggest_key_1: biggest_value_1, biggest_key_2: biggest_value_2}

Questions about programming?Chat with your personal AI assistant