Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

python language Please just show your code To get a list of all the files in the current directory as a list, use the following

python language

Please just show your code

To get a list of all the files in the current directory as a list, use the following imports in the your python program along with the following code snippet.

from os import listdir from os.path import isfile, join mypath = "docs/" # path to the folder that contains all the text files allfiles = [ f for f in listdir(mypath) if isfile(join(mypath,f)) ] 

The dictionary must be structured in such a way that the key of the dictionary is a word and the value for that key is a list of all the lines that contain that word in any of the files in the dictionary. For example, if the key is the word longitude, then the value for that word is a list that contains the following lines from the corresponding files.

['or Longitude I've got to?" (Alice had no idea what Latitude was, ', 'or Longitude either, but thought they were nice grand words to ', 'Within me latitude widens, longitude lengthens, ', 'ever Tom was short in longitude he had made up in ', 'about fifteen degrees of longitude since we left St. ', 'meant that we was closing up on the longitude of ', 'longitude on the EARTH?" '] 

For every file in the list of files obtained above (in the allfiles variable), open the file and add each word in the file to a dictionary unless that word is already in the dictionary. To ensure that your program works well for upper and lower case versions (for example, person and Person should both be the same keyword), convert every word to lower case before adding it to the dictionary. For each word, add a list or append to the list all the lines in the file that contain that word. Then close the file and go on to the next file, until your program has read all the files. Hint: Test the dictionary on one file first and look for the key and test the value for the key. Make sure that you are getting a list of all the lines in that single file that contain the word. To further test whether the dictionary in your program is working correctly, open the text file in Sublime Text and look for that word and search for the same word in that text file to verify the results.

After having processed all the files in the docs folder, write out only those key-values pairs to a file for those keys that are greater than 6 characters in length. The name of the output file should be dictionary-summary.txt.

Ask the user for the search keyword. Now, if the keyword exists in the dictionary that contains all the words, then display the value for that key in the dictionary. If that keyword does not exist in the dictionary, then let the user know that the provided keyword does not exist in the dictionary. Write out the results of the search operation to a file called searchResults.txt. For example, if the key exists then write out the key and the value (list of lines that contain the word) to the file searchResults.txt. If the key does not exist, then write out an appropriate message the to the file searchResults.txt.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Basics Computer EngineeringInformation Warehouse Basics From Science

Authors: Odiljon Jakbarov ,Anvarkhan Majidov

1st Edition

620675183X, 978-6206751830

More Books

Students also viewed these Databases questions

Question

Q: What steps are taken to reduce turnover?

Answered: 1 week ago