Ask Question
16 April, 12:13

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

Answers (1)
  1. 16 April, 12:30
    Python file with appropriate comments given below


    #Take the input file name

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

    #Open the input file

    inputFile = open (filename,"r+")

    #Define the dictionary.


    #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


    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]));
Know the Answer?