Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Im having problems understanding this assigments any help would be appreciated! Arranging and Presenting Data Using Dictionaries Scenario Given a word, write a function that

Im having problems understanding this assigments any help would be appreciated!

Arranging and Presenting Data Using Dictionaries

Scenario

Given a word, write a function that will output a dictionary that will give each character of the word and its frequency.

Aim

Due to its key-value pair format, dictionaries can be used to present some forms of structured data in an easily readable way. This challenge will help you write code to present frequency data for characters in strings.

Dictionaries are very good data structures for organizing data in a readable format. Your aim is to write a function calledword_counter, which will take in a line of text and output a dictionary with each letter as a key, the value being the frequency of appearance of the letter.

Here are some hints to help you out:

Treat different uppercase and lowercase letters separately. For example,Mandmshould have different counts.

Drop empty spaces.

Assume that sentences will not have any special characters.

Steps for Completion

  1. Define the functionword_counterand have it take a string argument.
  2. Iterate through the string and count the occurrences of each character.
  3. Output each character as a key in the output dictionary, with the frequency as the value.
  4. At the end of your script, call theword_counterfunction as shown inSnippet 6.46, pass it the string "Mississippi" and print it to the console. Here is an example:
print(word_counter("Mississippi")) 

  1. Run the script usingpython3 main.py, the output should look likeFigure 6.1:

Figure 6.1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

What items should be included in the audit status report?

Answered: 1 week ago