Read both part Q4a Q4b and Q4c before attempting the question You can submit part Q4a

Read both part Q4(a), Q4(b), and Q4(c) before attempting the question. You can submit part Q4(a), Q4(b), and Q4(c) together. Question 4a Create and write a function countRepeatingChar(word: string): int, that returns the highest number of the "repeating letter" in the given parameter word. Assume the given parameter word is in lowercase. For example, countRepeatingChar(word) returns these values for the following words as parameters: - assistants 4 - that 2 - business 3 - count 1 Write a function initializeDictionary(filename: string): dictionary, that reads the words from the given filename and returns the dictionary in the following format: stats={4:[assistants],2:[that,function,repeating,letters],3:[repeated,suss,business,assist],1:[count,word]} The key is the number of the "repeating letters", and the value is a list of words. Content of the file will be words separated by space. Each line may contain one or more words (all in lowercase). Example of a sample input file content: For each of the word read, find the highest number of the "repeating letter" for this word. Use this number as the key to the dictionary, to either build the list or append the word into the list. (13 marks) Create and implement a main function that calls the initializeDictionary function, and write selected content of the dictionary into another file, in this order and format: - ignore words that have no repeating letter, i.e., those words with key = 1 - in ascending order of the number of "repeating letters", followed by the list of words that have this number of repeating letters Sample output file: 2: that function repeating letters 3: repeated suss business assist 4: assistants (9 marks)

Read both part Q4(a), Q4(b), and Q4(c) before attempting the question. You can submit part Q4(a), Q4(b), and Q4(c) together.

Question 4a
Create and write a function countRepeatingChar(word: string): int, that returns the highest number of the “repeating letter” in the given parameter word. Assume the given parameter word is in lowercase. For example, countRepeatingChar(word) returns these values for the following words as parameters:
– assistants 4
– that 2
– business 3
– count 1

Write a function initializeDictionary(filename: string): dictionary, that reads the words from the given filename and returns the dictionary in the following format:
stats={4:[assistants],2:[that,function,repeating,letters],3:[repeated,suss,business,assist],1:[count,word]}

The key is the number of the “repeating letters”, and the value is a list of words. Content of the file will be words separated by space. Each line may contain one or more words (all in lowercase). Example of a sample input file content:

For each of the word read, find the highest number of the “repeating letter” for this word. Use this number as the key to the dictionary, to either build the list or append the word into the list. (13 marks)

Create and implement a main function that calls the initializeDictionary function, and write selected content of the dictionary into another file, in this order and format:
– ignore words that have no repeating letter, i.e., those words with key = 1
– in ascending order of the number of “repeating letters”, followed by the list of words that have this number of repeating letters

Sample output file:
2: that function repeating letters
3: repeated suss business assist
4: assistants (9 marks)


 
Solved By Verified
Study Co-Pilot All Study Co-Pilots are evaluated by Gotit Pro as an expert in their subject area.

 
Instant
Download

Student review: (5 ratings) 5 out of 5 people found this solution helpful.