# 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]))Sorting a Dictionary by Values
python
Related Posts
More content you might like
Code
javascript
Sorting an Array in JavaScript
No preview available for this content.
Jan 26, 2024
Read More Code
python
Sort List of Objects by Attribute in Python
No preview available for this content.
Jan 26, 2024
Read MoreDiscussion 0
Please sign in to join the discussion.
No comments yet. Be the first to share your thoughts!