Published on January 26, 2024By DeveloperBreeze

# Define a dictionary
my_dict = {'apple': 3, 'banana': 1, 'cherry': 2}

# Sort the dictionary by values using a lambda function
sorted_dict = dict(sorted(my_dict.items(), key=lambda item: item[1]))

Comments

Please log in to leave a comment.

Continue Reading:

Sort a List

Published on January 26, 2024

python

Sort List of Objects by Attribute in Python

Published on January 26, 2024

python

Sorting an Array

Published on January 26, 2024

javascript

Sorting an Array in JavaScript

Published on January 26, 2024

javascript