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
What was a result of george washington's belief in the sovereignty of the people instead of monarchy?
Ilya [14]
<span>George Washington's belief in the sovereignty of the people instead of monarchy led him to reject a third term as president.</span>
8 0
3 years ago
Urgent. I will mark you brainliest. explain why cyber warfare is a real threat.​
stellarik [79]

Answer: Cyber warfare is a real threat since being able to hack another computer especially a countries computer with lots of info in their weaknesses can lead to their downfall. Since they can even possibly if their skilled enough hack their entire data base system and leak it to the public and that wouldn't be good for them not in a single possible way. That's the reason it's dangerous not only that but also because they can access their servers; which can let them access anything online from the whole country including banking information military info which can let them know which area there gonna go to next equipment there gonna bring and where they're gonna launch missiles, bombs, even nukes if they decide to launch one. And being able to hijack the computer that launches the nukes can make the hacker launch the nuke to a different place or launch the nuke on the country trying to launch the nuke.

Explanation:

3 0
3 years ago
Read 2 more answers
Design a Visual Logic flowchart for a program that prompts the user to enter ten numbers one at a time. After the user has enter
swat32
N = 0 

<span>1 read x </span>

<span>n = n + 1 </span>

<span>print x </span>

<span>If n > 1, go down to 2 </span>

<span>small = x </span>
<span>large = x </span>

<span>2 If x</= small, then small = x </span>
<span>If x>/= large, then large = x </span>

<span>If n < 12 , go back up to 1 </span>

<span>Print small </span>
<span>Print large </span>
<span>end</span>
8 0
3 years ago
Individual mental blocks may cause option
Bond [772]

B. negative attitude option

3 0
3 years ago
Karen has found and removed all Web postings about her ex-boyfriend Bill. She has moved on. She’s now researching information ab
Naya [18.7K]

<u>Researching information about a project for work:</u>

The internet has a lot of information to offer when it comes to making a project about almost anything. There are a lot of web sites, posts,  articles, research papers, and even presentations about the topics that are most likely to be chosen for projects.

The best way to evaluate web sites about the content they offer is to know whether the site has an authorized or trusted source or  not.

There are platforms over the internet where people end up giving false information in the name of freedom of speech. The information conveyed should be genuine and supported by facts and figures.

6 0
4 years ago
Other questions:
  • Which step of creating a financial budget involves listing the payroll, rental, and utility costs?
    10·2 answers
  • 3.A customer has a system with a Gigabyte B450 Aorus Pro motherboard. He wants to upgrade the processor from the AMD Athlon X4 9
    11·1 answer
  • Using the expected format, of putting key information where the reader can’t find it, is an example of?
    8·2 answers
  • Assume that you want to create an array containing ten Die objects. Which of the following code segment accomplishes this correc
    11·1 answer
  • The process of using a computer to write, design, and assemble documents is called A. desktop publishing. B. scanning. C. consul
    7·1 answer
  • What term is used to describe the time it takes a signal to travel from one location to another on a network?
    13·1 answer
  • This is more opinionated than question-based.
    7·1 answer
  • Which is true about POP3 and IMAP for incoming email?
    14·1 answer
  • How does a author develop a character in a story?
    14·2 answers
  • Which is an example of an operating system? (5 points)
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!