Counting Letter Frequency in a String (Python)

后端 未结 12 2126
既然无缘
既然无缘 2020-12-01 17:52

I am trying to count the occurrences of each letter of a word

word = input(\"Enter a word\")

Alphabet=[\'a\',\'b\',\'c\',\'d\',\'e\',\'f\',\'g\',\'h\',\'i\'         


        
12条回答
  •  情话喂你
    2020-12-01 18:12

    def char_frequency(str1):
        dict = {}
        for n in str1:
            keys = dict.keys()
            if n in keys:
                dict[n] += 1
            else:
                dict[n] = 1
        return dict
    print(char_frequency('google.com'))
    

提交回复
热议问题