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
Ugo [173]
3 years ago
6

The program 4 should first tell users that this is a word analysis file. For any user-given text file, the program will read, an

alyze, and write each word with the line numbers where the word is found in an output file. A word may appear in multiple lines. A word shows more than once at a line, the line number will be only recorded one time.Ask a user to enter the name of a text file. Using try/except for invalid user input. Then the program reads the contents of the text file and create a dictionary in which the key-value pairs are described as follows:" Key. The key are the individual words found in the file. "Value. Each value is a list that contains the line numbers in the file where the word (the key) is found. Be aware that a list may have only one element.Once the dictionary has been built, the program should create another text file, named "word_index.txt". Next, write the contents of the dictionary to the file as an alphabetical listing of the words that are stored as keys in the dictionary (sorting the keys), along with the line numbers where the words appear in the original file. Please see the sample file for reference.Looking to seeing everyone to submit a well-done program! Here are some tips: "Documents/Comments of your program (Never more) "Testing your program by the given two files, Kennedy.txt and romeo.txt. The output file of the Kennedy.txt, "Kennedy_index.txt" and the output file for romeo.txt, "romeo_index.txt,. Please compare your program files with them. "Text File to be analyzed: romeo.txtArise: 5But: 1It: 3Juliet: 3Who: 7already: 7and: 3, 5, 7breaks: 1east: 3envious: 5fair: 5grief: 7is: 3, 7kill: 5light: 1moon: 5pale: 7sick: 7soft: 1sun: 3, 5the: 3, 5through: 1what: 1window: 1with: 7yonder: 1Text File to be analyzed: Kennedy.txtWe: 1a: 1, 2, 4an: 3as: 4, 5, 6beginning: 4but: 2celebration: 2change: 6end: 3freedom: 3not: 1observe: 1of: 2, 3party: 2renewal: 5signifying: 5symbolizing: 3today: 1victory: 1well: 4, 5romeo.txt But soft what light through yonder window breaks It is the east and Juliet is the sun Arise fair sun and kill the envious moon Who is already sick and pale with griefKennedy.txt We observe today not a victory of party but a celebration of freedom symbolizing an end as well as a beginning signifying renewal as well as change
Computers and Technology
1 answer:
djverab [1.8K]3 years ago
7 0

Answer:

See explaination

Explanation:

import os,string

def readfile(filename):

if os.path.isfile(filename) is not True:return None

line_number=1

word_dict={}

print('Text File to be analyzed: {}'.format(filename))

with open(filename,'r') as infile:

for line in infile.readlines():

words = line.strip().split()

for word in words:

word = word.strip(string.punctuation)

if word.strip()=='':continue

if word_dict.get(word)==None:

word_dict[word]=[line_number]

else:

line_number_list=word_dict.get(word)

line_number_list.append(line_number)

line_number+=1

return word_dict

def write_to_file(word_dict,filename):

with open(filename,'w') as outfile:

for word in sorted(word_dict.keys()):

outfile.write('{0}:\t\t{1}\n'.format(word,','.join([str(n) for n in word_dict.get(word)])))

def main():

filename='D:\\Word.txt'

output_filename='D:\\word_index.txt'

word_dict = readfile(filename)

if word_dict ==None:

print('Unable to read file {}'.format(filename))

else:

for word in sorted(word_dict.keys()):

print('{0}:\t\t{1}'.format(word,','.join([str(n) for n in word_dict.get(word)])))

write_to_file(word_dict,output_filename)

main()

You might be interested in
A growing number of large organizations have built internal Web sites that provide opportunities for online social networking am
Flauer [41]

Answer:

True

Explanation:

The ideology of building internal web sites  for online social networking among employees is aimed towards productivity.

<em>For example, when an employee is finding a specific job difficult and is connected with someone on the social websites created by the organization, the employee will get help in no time to ensure that the organization achieve maximum productivity.</em>

It will constantly keep each employee informed on the organizations policies, goals and achievements.

However, there are shortcomings of online social networking in the workplace:

  1. If not properly managed, It might become addictive and will lead to low employee productivity.
  2. Great intellectual minds might be exposed to negative influences from within the organisation

8 0
3 years ago
C:/Users/Documents/resume.docx Where is the "resume" document located in this file structure?
ASHA 777 [7]

Answer:

"resume.docx" is located in "Documents"

Explanation:

[<drive-letter:: represents drive name>]:/Main_Directory/Sub_Directory/ETC..

3 0
3 years ago
Which of the following has likely attended vocational school?
JulsSmile [24]

C- A graphic designer is the awnser

7 0
3 years ago
Help ASAP!!Choose all the basic elements of algorithms. A.Selection B.Loops C.Flow Charts D.Sequencing E.Combinations F.Iteratio
serg [7]

Answer:

b c d

Explanation:

8 0
3 years ago
Read 2 more answers
HELPPP ME PLEASEEE!!
natita [175]
It’s the last one! The key to an effective persuasion is to know what you want and be clear about your response.
4 0
3 years ago
Other questions:
  • What is the force generated by a rocket motor to propel a spacecraft forward?
    14·1 answer
  • Write a program that reads a file containing text. Read each line and send it to the output file, preceded by line numbers. If t
    8·1 answer
  • Your friend sees an error message during Windows startup about a corrupted bootmgr file. He has another computer with a matching
    12·1 answer
  • What is the top folder of the file tree called
    5·2 answers
  • What should be a technicians first step in an A/C system
    7·1 answer
  • Every command or instruction is called
    8·2 answers
  • You are planning a storage solution for a new Windows server. The server will be used for file and print services and as a datab
    6·1 answer
  • For which input values will the following loop not correctly compute the maximum of the values? 1. Scanner in = new Scanner (Sys
    14·1 answer
  • You can open a movie maker project file any time in a media player. (1 point) true false
    6·1 answer
  • processing C. have only one function, e.g. control traffic lights in a town, games machines 7 To create a formula, you first: A.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!