При этом мне нужно не только посчитать частоту букв в слове, но и выложить неиспользуемые буквы.
alphabetList = ["a","b","c","d","e","f","g","h","i","j","k",\
"l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
def Checksums():
for i in alphabetList:
character = i
myString = Phrase
myList = []
for i in myString:
myList.append(i)
myList = myList.sort()
print myList
count = 0
for i in myList:
if i == character:
count = count +1
else:
continue
print("There are ", count, " occurrences of ", character )
#input
Phrase = str(raw_input("Enter a Phrase: "))
Phrase = Phrase.lower()
# print (Phrase)
Phrase = Phrase.replace(" ", "")
# print Phrase
Checksums()
Пример ввода может быть:
aaA cC D <br>
и возвращаемое значение будет
"There were '3' occurrences of the letter 'a'"<br>
"There were '2' occurrences of the letter 'c'"<br>
"Only 1 'd'"<br>
"The remaining letters are unused": b, e, etc...
Я попытался использовать список алфавитов и просто перебрать его, но я получаю следующую ошибку:
TypeError: объект 'NoneType' не повторяется