Menu
CoddyTech

Recap - Dictionary Sorter

Part of the Logic & Flow section of Coddy's GDScript journey. Lesson 52 of 78.

challenge icon

Challenge

Medium

Write 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

Practice on your own: Online GDScript compiler