answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
lozanna [386]
1 year ago
12

A file concordance tracks the unique words in a file and their frequencies. Write a program that displays a concordance for a fi

le. 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
I AM SAM I AM SAM SAM I AM
Enter the input file name: example.txt
AM 3
I 3
SAM 3

Computers and Technology
1 answer:
victus00 [196]1 year ago
6 0

Answer:

I am writing a Python program.

def concordance(filename):  # function that takes a file name as parameter and returns the concordance for that file

   file = open(filename,"r")  #opens file in read mode

   unique={}  #creates and empty list

   for word in file.read().split():  #loops through every word in the file

       if word in unique:  # if words is already present in the list

           unique[word] += 1  #add 1 to the count of the existing word

       else:    #if word is not present in the list

           unique[word] = 1 #add the word to the list and add 1 to the count of word

           file.close();  # close the file

   for x in sorted(unique):  #sort the list and displays words with frequencies

       print(x, unique[x]);  #prints the unique words and their frequencies in alphabetical order

#prompts user to enter the name of the file

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

concordance(file_name)  #calls concordance method by passing file name to it

Explanation:

The program has a function concordance that takes a text file name as parameter and returns a list of unique words and their frequencies.

The program first uses open() method to open the file in read mode. Here "r" represents the mode. Then creates an empty list named unique. Then the for loop iterates through each word in the file. Here the method read() is used to read the contents of file and split() is used to return these contents as a list of strings. The if condition inside the loop body checks each word if it is already present in the list unique. If the word is present then it adds 1 to the count of that word and if the word is not already present then it adds that unique word to the list and assign 1 as a count to that word. close() method then closes the file. The second for loop for x in sorted(unique):  is used to display the list of unique words with their frequencies. sorted() method is used to sort the list and then the loop iterates through each word in the list, through x, which acts like an index variable, and the loop displays each word along with its frequency.

You might be interested in
in a small office, there are 5 computers, a network printer, and a broadband connection to the internet. what devices are needed
Nataly [62]

Answer:

<em>Ethernet cables, Network Adapters, Modem, Routers, Switches.</em>

Explanation:

<em>The devices that are required in setting up a wired network for the 5 computer comprises of the following devices </em>

  • <em>Ethernet Cables</em>
  • <em>Network Adapters</em>
  • <em>Modem/Router</em>
  • <em>Network Switch</em>

<em>Ethernet cables: They are called network cables or RJ-45 cables used to in connecting two or more computers together. it has different categories called, the untwisted pair and twisted pair Ethernet, with a speed from 10-1000</em>

<em>Network Adapters : This adapters allows a computer device to connect and interface with a network computer</em>

<em>Modem/Routers : A router is a device that that sits in the  middle  between your local computers and modems. it takes receives information or gets information from the modem and delivers it to the computer</em>

<em>Network switch: it connects more than two computers together to a network and share data among themselves and other devices on the network</em>

6 0
2 years ago
In object oriented programming, what is another name for the "attributes" of an object?
Ket [755]
I believe the word you're looking for is properties.
7 0
1 year ago
A ____ partition contains the data necessary to restore a hard drive back to its state at the time the computer was purchased an
Oxana [17]
The answer is back up
8 0
1 year ago
Read 2 more answers
Digital cellphones use __________ to reduce the size of the channels that are required by scattering the digital fragments of co
Yuri [45]

Digital cellphones use Digital Compression to reduce the size of the channels that are required, by scattering the digital fragments of conversations over many channels

7 0
1 year ago
Consider the following 3-PARTITION problem. Given integers a1; : : : ; an, we want to determine whether it is possible to partit
ZanzabumX [31]

Answer:

Explanation:

Find attach the solution

6 0
1 year ago
Other questions:
  • Computer design software requires __________________ to be used properly and successfully by architects.
    9·2 answers
  • Which statements describe the advantages of using XML?
    12·2 answers
  • During which phase of web publishing would you use a text editor to enter codes that instruct the browser how to display webpage
    5·1 answer
  • Mathematical computations by a computer are faster than your quickest mathematical computations because the top speed of a neura
    13·1 answer
  • Brian drives a car that uses voice commands for navigation. Which field did researchers use to develop a car-based AI that under
    10·1 answer
  • Which two factors most influenced the growth of the Internet during the 1970s?
    7·2 answers
  • A(n) ____ attack is when a system is compromised and used to attack other systems. a. indirect b. direct c. object d. subject
    13·1 answer
  • Using Amdahl’s Law, calculate the speedup gain of an application that has a 60 percent parallel component for (a) two processing
    11·1 answer
  • Nstructions
    7·1 answer
  • Put the steps in order to produce the output shown below. Assume the indenting will be correct in the program.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!