Recap - Frequency Counter
Part of the Logic & Flow section of Coddy's GDScript journey. Lesson 23 of 78.
Challenge
EasyWrite 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
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