Cody Bable

Generation

generate functionFri, 30 Jun 2023

return the two biggest numbers in a list of dictionaries

def return_key(a, b): return a[b] def name_score(list_dict, key): max_score = max(list_dict, key = lambda x: return_key(x, key)) list_dict.remove(max_score) max_score2nd = max(list_dict, key = lambda x: return_key(x, key)) return max_score, max_score2nd list_dict = [{'name': 'Tom', 'score': 10}, {'name': 'Jerry', 'score': 5}, {'name': 'Micky', 'score': 8}] key = 'score' name_score(list_dict, key)

Questions about programming?Chat with your personal AI assistant