Programming Examples
Python program to count the number of times a character appears in a given string
Write a program to count the number of times a character appears in a given string
Solution
mystr = input("Enter any String : ")
mydic = { }
for i in mystr :
mydic [ i ] = mystr.count( i )
print(mydic)
Output/ Explanation:
Enter any String : infomax computer academy
{'i': 1, 'n': 1, 'f': 1, 'o': 2, 'm': 3, 'a': 3, 'x': 1, ' ': 2, 'c': 2, 'p': 1, 'u': 1, 't': 1, 'e': 2, 'r': 1, 'd': 1, 'y': 1}