How to count the number of letters in a string without the spaces?

后端 未结 13 990
梦谈多话
梦谈多话 2020-12-31 07:45

This is my solution resulting in an error. Returns 0

PS: I\'d still love a fix to my code :)

from collections import Counter
import          


        
13条回答
  •  误落风尘
    2020-12-31 08:35

    def count_letter(string):
        count = 0
        for i in range(len(string)):
            if string[i].isalpha():
                count += 1
        return count
    
    
    print(count_letter('The grey old fox is an idiot.'))
    

提交回复
热议问题