Ask Question
17 January, 12:13

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.

+4
Answers (1)
  1. 17 January, 15:13
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers