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}

Latest Current Affairs 2024 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad