Word Analytics
Part of the Logic & Flow section of Coddy's GDScript journey. Lesson 77 of 78.
Challenge
HardWrite the function analyze_text(text) above _ready(). It analyzes the words of a text and returns a dictionary. The given _ready() reads one line of text, calls your function and prints the result.
Prepare the words first:
- Words are case-insensitive:
Helloandhelloare the same word, so work in lowercase - Remove these characters from the text:
. , ! ? : ; " ( ) - Words are separated by spaces, and an empty text has no words
Return a dictionary with three keys, in this order:
"unique_count": the number of different words"repeated_words": an array of the words that appear more than once"palindromes": an array of the different words that read the same backwards, such aslevelora
Each word appears once in an array, and both arrays are sorted alphabetically. For the text below:
Madam saw a racecar. Dad said hello hello to mom.the output is:
{ "unique_count": 9, "repeated_words": ["hello"], "palindromes": ["a", "dad", "madam", "mom", "racecar"] }Try it yourself
extends Node
func analyze_text(text: String):
# Write your code here
pass
func _ready():
var text := OS.read_string_from_stdin()
print(analyze_text(text))
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