Ask Question

Create a dictionary called low_d that keeps track of all the characters in the string p and notes how many times each character was seen. Make sure that there are no repeats of characters as keys, such that "T" and "t" are both seen as a "t" for example.

+5
Answers (1)
  1. 24 October, 00:15
    0
    from collections import defaultdict #importing defaultdict

    low_d=defaultdict (int) #declaring an empty dictionary

    string=str (input ("Enter your string / n")) #taking input of the string ...

    for i in string:#iterating over the string ...

    low_d[str. lower (i) ] + = 1 #adding the character in lowercase and increasing it's count ...

    for key, value in low_d. items () : #iterating over the dictionary.

    print (key+":"+str (value)) #printing the key value pair ...

    Output:-

    Enter your string

    ramaranR

    n:1

    m:1

    a:3

    r:3

    Explanation:

    I have declared an empty dictionary using defaultdict then I have ask the user to input the string. Then I iterated over the string and added each character to the dictionary and updated it's count. Then printing the characters and their frequency.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Create a dictionary called low_d that keeps track of all the characters in the string p and notes how many times each character was seen. ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers