213k views
5 votes
A file concordance tracks the unique words in a file and their frequencies. write a program that displays a concordance for a file. the program should output the unique words and their frequencies in alphabetical order.

User Ankush Roy
by
8.1k points

1 Answer

5 votes
f = "HELLO HELLO HELLO WHAT ARE YOU DOING"
myDict = {}
linenum = 0

for word in f.split():
if not word in myDict:
myDict[word] = []

myDict[word].append(linenum)


print "%-15s %-15s" %("Word", "Frequency")
for key in sorted(myDict):
print '%-15s: %-15d' % (key, len(myDict[key]))
User Eunice
by
8.0k points