Question: #Take the input file name filename=input('Enter the input file name: ') #Open the input file inputFile = open(filename,r+) #Define the dictionary. list={} #Read and split
#Take the input file name
filename=input('Enter the input file name: ')
#Open the input file
inputFile = open(filename,"r+")
#Define the dictionary.
list={}
#Read and split the file using for loop
for word in inputFile.read().split():
#Check the word to be or not in file.
if word not in list:
list[word] = 1
#increment by 1
else:
list[word] += 1
#Close the file.
inputFile.close();
#print a line
print();
#The word are sorted as per their ASCII value.
fori in sorted(list):
#print the unique words and their
#frequencies in alphabetical order.
print("{0} {1} ".format(i, list[i]));
Can someone help me fix this code? I'm using python.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
