Menu
CoddyTech

Recap - Frequency Counter

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

challenge icon

Challenge

Easy

Write a function named frequency_counter with one parameter, data_list: an array of numbers and strings. It counts how many times each item appears and returns a dictionary: the keys are the different items, in the order they first appear, and each value is the count of that item.

For example, frequency_counter([1, 2, 2, 3, 3, 3]) returns {1: 1, 2: 2, 3: 3}, and frequency_counter(["apple", "pear", "apple"]) returns {"apple": 2, "pear": 1}. An empty array gives an empty dictionary.

The tests call frequency_counter() themselves and check the returned dictionary. Do not call it and do not print anything.

Try it yourself

func frequency_counter(data_list: Array):
	# Write code here
	pass

All lessons in Logic & Flow

Practice on your own: Online GDScript compiler