Cody Bable

Generation

generate functionFri, 30 Jun 2023

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

def top_three(input): return sorted(input, key=lambda k: k['value'], reverse=True)[:3] l = [ {'name': 'Hector', 'value': 20}, {'name': 'Gandalf', 'value': 100}, {'name': 'John', 'value': 12}, {'name': 'Aaron', 'value': 3} ] top_three(l)

Questions about programming?Chat with your personal AI assistant