Hello I am new to programming, and I need some help improving this code. I need to count how many times each letter of the alphabet occurs in the file and ignore the case of the letter; an 'A'
and an 'a'
are both counted as 'A'
. The output needs to look like this something like this:
>A 20
>B 3
>C 5
This what I have so far:
file = open("LETTERCOUNT.txt", "w")
file.write("My name is Alexis Bernal, yet some people call me Lexi. I am currently eighteen years old. I really enjoy snowboarding, working out, hanging out with friends and trying new food. My favorite color is burgundy and my favorite animal is a giraffe. ")
import string
text = open('LETTERCOUNT.txt').read()
text = filter(lambda x: x in string.letters, text.lower())
for letter, repetitions in file:
print (letter, repetitions)