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. Variations are to track sequences of two words and their frequencies, or n words and their frequencies. Below is an example file along with the program input and output: example.txt

Respuesta :

Answer:

Python file with appropriate comments given below

Explanation:

#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]));

fichoh

The program which produces a sorted output of words and frequency based on a read on text file is written in python 3 thus :

filename = input('Enter the your file name : ')

#accepts user input for name of file

input_file = open(filename,"r+")

#open input file in read mode

list= dict()

#initialize an empty dictionary

for word in input_file.read().split():

#Read each line and split the file using for loop

if word not in list:

list[word] = 1

#increment by 1

else:

list[word] += 1

#if word already exists in dictionary increase frequency by 1, if not assign a frequency of 1

input_file.close();

#close the file

for i in sorted(list):

print("{0} {1} ".format(i, list[i]));

#loop through and display the word and its corresponding frequency

Learn more : https://brainly.com/question/19114739