1answer.
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]
3 years 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]3 years 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
Write a statement that calls a function named IncreaseItemQty, passing the variable addStock. Assign mugInfo with the value retu
PolarNik [594]

Answer:

Explanation:

#include <stdio.h>

#include <string.h>

typedef struct ProductInfo_struct {

char itemName[30];

int itemQty;

} ProductInfo;

ProductInfo IncreaseItemQty (ProductInfo productToStock, int increaseValue) {

productToStock.itemQty = productToStock.itemQty + increaseValue;

return productToStock;

}

int main(void) {

ProductInfo mugInfo;

int addStock;

addStock = 10;

scanf("%s", mugInfo.itemName);

scanf("%d", &mugInfo.itemQty);

**** /* Your solution goes here */ ****

printf("Name: %s, stock: %d\n", mugInfo.itemName, mugInfo.itemQty);

return 0;

}

8 0
3 years ago
Ebay employs the _____ auction mechanism.
myrzilka [38]

Answer:

A. Foward

Explanation:

4 0
3 years ago
Read 2 more answers
what is the term used when a virus takes control of features on your computer and transports files or information automatically?
Akimi4 [234]

Answer: a "worm"

Explanation:

3 0
3 years ago
Brianna has a physical store that she's successfully managed for 10 years. Her products aren't designed to sell and ship online.
Jet001 [13]

Answer:

Brianna can measure offline sales initiated from an ad click.

Explanation:

A customer’s interaction with you can start online and then finish in your local store or physical business location. So, keeping track of everything will provide better view about your product.

4 0
4 years ago
Which component is in discreat type? A.power IC B.regular IC C.Resistor D.digital IC​
Finger [1]

Answer:

C. Resistor

Explanation:

A discrete component can be defined as any electronic component that are built as an individual or single unit.

Basically, a discrete component comprises of a single circuitry element, either an active element such as a vacuum tube, transistor etc or a passive element such as a resistor, diode, capacitor, inductor etc.

Hence, a discrete component is different from an integrated circuit (IC) or hybrid circuits because it is typically constructed or built with a single circuit element while integrated or hybrid circuits are constructed as a multiple unit.

Additionally, most discrete component are mainly semiconductors and as such consume large amounts of current.

5 0
3 years ago
Read 2 more answers
Other questions:
  • What limits the impact of vehicle balance on view ghost ability during emergency vehicle maneuvers?
    15·1 answer
  • Which option enables you to keep the last grammatical change
    15·2 answers
  • Which of the following experiences is considered a simulation?
    12·1 answer
  • C++ what is wrong with my equation?
    10·1 answer
  • What is pure carbon made of
    14·2 answers
  • Information about a computer file, not the actual data that is contained in the file, is called ______
    8·2 answers
  • Python: initalize the variable first_name with the value from the user prompt "What is your first name? " initalize the variable
    9·1 answer
  • What happens if none of the selector values match selector in a simple case expression in pl/sql
    6·1 answer
  • Assume myString and yourString are variables of type String already declared and initialized. Write ONE line of code that sets y
    15·1 answer
  • What is computer forensics? Where and how would an IT auditor use thisresource?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!