Question

python3.x Write a function print_letter_count(word) that takes a string as a parameter and prints each unique...

python3.x

Write a function print_letter_count(word) that takes a string as a parameter and prints each unique character (in alphabetical order and lowercase) together with their frequency. For example: consider the following word:

Programming

The characters are: 1 x p, 2 x r, 1 x o, 2 x g, 1 x a, 2 x m, 1 x i and 1 x n. The output would be:

a: 1
g: 2
i: 1
m: 2
n: 1
o: 1
p: 1
r: 2

Note:

  • The parameter string may contain uppercase letters
  • The output is in alphabetical order.

For example:

Test Result
print_letter_count('Programming')
a: 1
g: 2
i: 1
m: 2
n: 1
o: 1
p: 1
r: 2
print_letter_count('Combination')
a: 1
b: 1
c: 1
i: 2
m: 1
n: 2
o: 2
t: 1
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hey here is answer to your question.

In case of any doubt comment below. if you liked the answer feel free to upvote this.

Explanation :- how it works is we take a string and we make a dict in python. then we loop over the string and check if its exist in dict then increase the counter.

def print_letter_count(string):
   string =string.lower()
   answer = {}
  
   for i in string:
   if i in answer:
   answer[i] += 1
   else:
   answer[i] = 1
   for i in sorted(answer.keys()):
      print(str(i) + " : "+str(answer[i]))


#print_letter_count('Programming')
print_letter_count('Combination')

Add a comment
Know the answer?
Add Answer to:
python3.x Write a function print_letter_count(word) that takes a string as a parameter and prints each unique...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • IN PYTHON Implement a function easyCrypto() that takes as input a string and prints its encryption...

    IN PYTHON Implement a function easyCrypto() that takes as input a string and prints its encryption defined as follows: Every character at an odd position i in the alphabet will be encrypted with the character at position i + 1, and every character at an even position i will be encrypted with the character at position i - 1. In other words, ‘a’ is encrypted with ‘b’, ‘b’ with ‘a’, ‘c’ with ‘d’, ‘d’, with ‘c’, and so on. Lowercase...

  • Write a static method called printWithSpaces that takes a String as its parameter and prints the...

    Write a static method called printWithSpaces that takes a String as its parameter and prints the characters of the string separated by spaces. For example: > Methods.printWithSpaces("method") m e t h o d You should have a single space after the last character. This method should not return a value. That is similar to this code for printing the string vertically public static void printVertical(String s) { for (int i = 0; i < s.length(); i++) { char c =...

  • 2. Searching a String: Write a MIPS assembly language program to do the following: Read a...

    2. Searching a String: Write a MIPS assembly language program to do the following: Read a string and store it in memory. Limit the string length to 100 characters. Then, ask the user to enter a character. Search and count the number of occurrences of the character in the string. The search is not case sensitive. Lowercase and uppercase letters should be equal. Then ask the user to enter a string of two characters. Search and count the number of...

  • 2) Write a function stringManip that takes in a character string and returns a character string...

    2) Write a function stringManip that takes in a character string and returns a character string following these rules: a) any vowel (a, e, i, o, u) is replaced by the character '&' b) any numeric character has 1 added to it (if it was 9, it becomes O instead) (str2num() is useful here) c) all lowercase characters become uppercase d) replace the final character with '!' e) append the length of the string before this step to the end...

  • Write an LC-3 program (starting at memory location 0x3000) to take a string as input and...

    Write an LC-3 program (starting at memory location 0x3000) to take a string as input and then output information about this string. The end of the string will be denoted with the "#" character. Once the "#" has been found, output the following in order: 1) The letter “u” followed by the number of uppercase letters in the string (A-Z) 2) The letter “l” followed by the number of lowercase letters in the string (a-z) 3) The letter “n” followed...

  • 10. replaceSubstring Function Write a function named replaceSubstring. The function should accept three C-string or string...

    10. replaceSubstring Function Write a function named replaceSubstring. The function should accept three C-string or string object arguments. Let's call them string1, string2, and string3. It should search string for all occurrences of string2. When it finds an occurrence of Programming Challenges string2, it should replace it with string. For example, suppose the three arguments have the following values: stringt: "the dog jumped over the fence" string 2 "the" string3: "that" With these three arguments, the function would return a...

  • Methods: Net beans IDE Java two methods. Identifier: calculateScore(String word) Parameters: word – the word for...

    Methods: Net beans IDE Java two methods. Identifier: calculateScore(String word) Parameters: word – the word for which you should calculate the points in Scrabble Return Value: int – the number of points for the parameter word Other: This method should be static. This method should use the following system for scoring: 0 – blank 1 – e, a, i, o, n, r, t, l, s, u 2 – d, g 3 – b, c, m, p 4 – f, h,...

  • Write a function named vertical that accepts a string as its parameter and prints each letter...

    Write a function named vertical that accepts a string as its parameter and prints each letter of the string on separate lines. For example, a call of vertical("hey now") should produce the following output: h e y n o w

  • use c code to Develop a function void printToggled(char str[]) that gets a string as a...

    use c code to Develop a function void printToggled(char str[]) that gets a string as a parameter and prints every lowercase character as an uppercase one and vise versa. For example, if the string submitted as a parameter is Hello WorlD! The function should print hELLO wORLd! Hint:answer must include output

  • Python3 : Write the function longestRun(s, chars) that takes a possibly-empty string s and a second...

    Python3 : Write the function longestRun(s, chars) that takes a possibly-empty string s and a second possibly-empty string of chars. We will say that a character is "good" if it is in the chars string (case insensitively, so "A" and "a" would match). The function should return the length of the longest consecutive run of good characters in the given string s. For example, consider: longestRun("abbcazBbcababb","bz"). This returns 3 (look for "zBb"). Restrictions: for loop, slicing cannot be used, if...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT