Cody Bable

Generation

generate functionFri, 30 Jun 2023

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

def biggest_in_list(list_of_dicts): max1 = list_of_dicts[0] max2 = list_of_dicts[0] for i in list_of_dicts: if i['number'] > max1['number']: max2 = max1 max1 = i elif i['number'] > max2['number']: max2 = i return [max1, max2] biggest_in_list([{'name': 'A', 'number': 1}, {'name': 'B', 'number': 10}, {'name': 'C', 'number': 100}])

Questions about programming?Chat with your personal AI assistant