the-honk/school/a-level/y12 2022-2024/Homework/07-12-22 - Dictionaries/Letter Frequency.py

17 lines
368 B
Python

from typing import Dict
import re
def letterFrequency(text: str) -> Dict[str, int]:
output = {}
text = re.sub('[^a-zA-Z]+', '', text)
for letter in text:
if letter in output:
output[letter] += 1
else:
output[letter] = 1
return output
frequency = letterFrequency('I wish I wish with all my heart to fly with dragons in a land apart')
print(frequency)