Saturday, 10 August 2013

Counting Frequency of Letters in a file and writing to a output file python

Counting Frequency of Letters in a file and writing to a output file python

I am writing a function that take a in_file and checks the frequency of
the letters in that file and writes in this format (letter:frequency) to a
out_file.This is what i got so far can anyone help?
def count_letters(in_file,out_file):
in_file = open(in_file,"r")
out_file = open(out_file,"w")
for line in in_file:
words = line.split()
for word in words:
for letter in word:
print(letter,':',line.count(letter),file=out_file,end="\n")

No comments:

Post a Comment