How to count the number of letters in a string without the spaces?
python
Solution
def count_letters(word):
return len(word) - word.count(' ')
Alternatively, if you have multiple letters to ignore, you could filter the string:
def count_letters(word):
BAD_LETTERS = " "
return len([letter for letter in word if letter not in BAD_LETTERS])
Problem
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 string def count_letters(word): global count wordsList = string.split(word) count = Counter() for words in wordsList: for letters in set(words): return count[letters] word = "The grey old fox is an idiot" print count_letters(word) ```