Crazyy.Net Crazyy.Net - 1 year ago 141
Python Question

Count character occurrences in a Python string

I want to get the each character count in a given sentence. I tried the below code and I got the count of every character but it displays the repeated characters count in the output. How to delete repeated character.

def countwords(x):
for i in x:

x=str(input("Enter a paragraph "))

My output is:

enter image description here

My output should not contain spaces count and repeated characters.. What to do....!!!

Answer Source

check this code :

my_string = "count a character occurance"
my_list = list(my_string)
print (my_list)
get_unique_char = set(my_list)
print (get_unique_char)

for key in get_unique_char:
    print (key, my_string.count(key))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download