48.6k views
1 vote
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.

User Rayncorg
by
6.0k points

1 Answer

5 votes

Answer:

from collections import defaultdict #importing defaultdict

low_d=defaultdict(int)#declaring an empty dictionary

string=str(input("Enter your string \\"))#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

Step-by-step 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.

User Nicobatu
by
5.7k points