Recap - Dictionary Sorter
Part of the Logic & Flow section of Coddy's Python journey — lesson 49 of 78.
Challenge
MediumCreate a function named dictionary_sorter that takes a dictionary data_dict as an argument. The function should sort the dictionary by its values in ascending order and return a new dictionary containing the sorted key-value pairs.
For example, if the input dictionary is {'a': 3, 'b': 1, 'c': 2}, the function should return a dictionary like this:
{'b': 1, 'c': 2, 'a': 3}Try it yourself
def dictionary_sorter(data_dict):
# Use sorted() to sort the dictionary items by their values
# Hint: data_dict.items() returns (key, value) pairs
# Hint: Use the 'key' parameter of sorted() to sort by value
# Write code hereAll lessons in Logic & Flow
1Variables Exploration
ConstantsMultiple Variable AssignmentsSwapping VariablesPlaceholder VariablesRound NumbersList Casting4Contact Book Application
Display MenuAdd Contact7Sets Part 2
Mathematical Operations Part 1Mathematical Operations Part 2Recap - Treasure HuntSubsets and SupersetsIterating Over SetsRecap - Tournament Tracker2Dictionaries Part 1
What is a Dictionary?Creating a DictionaryAccessing ValuesModifying DictionariesRecap - Recipe Manager5Advanced Decision Making
Ternary OperatorMembership ChecksIdentity ChecksIndentation ErrorsRecap - Vacation Filter8Student Records Manager
Project OverviewAdd Student11Advanced Functions
Returning Multiple ValuesLambda Functions Part 1Lambda Functions Part 2Recap Challenge - Lambda SortRecursive Functions Part 1Recursive Functions Part 2Recap - Sum Nested List14Higher-Order Functions
The Map FunctionThe Filter FunctionRecap - Email ValidatorRecap - Number Processor3Dictionaries Part 2
Dictionary MethodsNested DictionariesChecking for KeysLooping Through DictionariesRecap - Frequency Counter9Advanced Data Aggregation
Using SumFinding Minimum and MaximumSorting Data EfficientlyRecap - Dictionary Sorter