Q. Write a program to count the number of times a character appears in a given string.
Answer :-
string = input("Enter String :- ") dic = { } for i in string : dic [ i ] = string.count( i ) print(dic)
Output:-
Enter String :- Pathwalla
{'P': 1, 'a': 3, 't': 1, 'h': 1, 'w': 1, 'l': 2}
{'P': 1, 'a': 3, 't': 1, 'h': 1, 'w': 1, 'l': 2}
>>>
Enter String :- Mississippi
{'M': 1, 'i': 4, 's': 4, 'p': 2}
>>>
wow
ReplyDeleteThank you : ) ^_^
DeleteThank u bro^_^
ReplyDeleteWelcome : ) ^_^
DeleteThank you
ReplyDeleteWelcome 😊😊
Deleteis therre any way to do without count statement?
ReplyDeleteYes, you can also use nested loop.
DeletePlease post a output also I some question it have but in many it don't have for ex: this question
ReplyDeleteOk, Please tell me more question.
Deletemay I know other statements
ReplyDeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )