Recap - Dictionary Sorter
Part of the Logic & Flow section of Coddy's GDScript journey. Lesson 52 of 78.
Challenge
MediumWrite a function named dictionary_sorter with one Dictionary parameter, data, whose values are whole numbers. It returns a new dictionary with the same pairs, ordered by value from smallest to largest. A dictionary keeps its pairs in the order they were added, so the order you insert them in is the order they keep.
For example, for {"a": 3, "b": 1, "c": 2} it returns:
{"b": 1, "c": 2, "a": 3}No two values in a test are equal. The tests call dictionary_sorter() themselves and show the dictionary it returns. Do not call it, and do not print anything. The file needs only your functions: no extends Node and no _ready().
Try it yourself
func dictionary_sorter(data: Dictionary):
# Write code here
pass
All lessons in Logic & Flow
1Strings In Depth
String MethodsSearching in StringsReplace and TrimSplit and JoinRecap - Username Check4Dictionaries Part 2
Nested DictionariesArrays of DictionariesMerging DictionariesCopying DictionariesRecap - Frequency Counter2Advanced Decision Making
Match With VariablesMatch GuardsArray PatternsDictionary PatternsMembership ChecksRecap - Command Parser5Contact Book Application
Display MenuAdd Contact8Student Records Manager
Project OverviewAdd Student3Multi-dimensional Arrays
2D Arrays BasicsAccessing 2D Array ElementsNested Loops with 2D ArraysRecap - 2D ArraysJagged ArraysCommon 2D Array PatternsRecap - Game Board6Sets with Dictionaries
What is a Set?Dictionary as a SetAdding and RemovingUnion and IntersectionSet DifferenceRecap - Remove Duplicates9Advanced Data Aggregation
Summing ValuesFinding Minimum and MaximumCustom SortingRecap - Dictionary SorterPractice on your own: Online GDScript compiler