Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using python, write a program that allows your user to search for all the occurrences of a word in a collection of documents. 1. Download

Using python, write a program that allows your user to search for all the occurrences of a word in a collection of documents.

1. Download the text files "How to make a dry ice bomb", "Guide to Anarcy", and "Department Store Fun reprinted from TAP Magazine"

2. 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. #What exactly is this part asking for?

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)) ]

3. The dictionary must be structured so 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. Eg: 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.

[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?" ']

4. For this part, for every file in the list of files obtained above (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.

5.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 dict_summary.txt.

6. Here, you will ask the user for the search keyword. 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.

Here are the 3 text files that had to be downloaded

- How to make a dry ice bomb -

This is one of the most simple bombs to make. It is used for many different things. If your just out having fun take a two liter soda bottle and fill it three quarters with water. Then take a piece of dry ice and crush it. Put just enough to make a layer at the bottom of the jug. Now cap it and run! You wil have about 10 to 15 sec before it detonates. It will make quite a boom! I set of a car alarm 30 - 40 feet away with one of these! Now if you are in a war or need one for self defense you can do the same procedure exept use a glass bottle. this will throw glass shrapnel, so it can do some damage on a human. Do not in any way use this on a person unless you are AT WAR!!!! So be careful!! **CAUTION** There is no set time for detonation so it is NOT wise to hold in your hand!!!! Here are a few other things you can do with dry ice:

1. Mix 1 part egg, 1 part paint, 1 part, wipped cream, and fill a two litter bottle with it. Put about two inches of dry ice in the bottom. Cap it and get creative.

-Guide to Anarcy-

If you truly want to be a great anarcist there are a few guidelines you must live-by. These are 10 undeniable things that should be a part of your life if you truly want to mess with society. There is always room to expand on the ideas and sick plans of Chaos presented in this little creation of my obviousy demented head. Well here they are, don't doubt there potental to mold you into a sick, and troubled individual. 1. First of all, never show that you have any other aspiration in life other than to go to prison then, upon your execution, burn in hell, disguising the fact that you are an ingenious anarcist ploting world domination.[or so I hope, but otherwise stop reading loser!!!] 2. Always do the exact opposite of the average law abiding citizen [like puting dead and decaying, furry little woodland creatures in your neighbor's mailbox] This is an important part of an anarcist life, never doubt it.

-Department Store Fun reprinted from TAP Magazine. By Agent 81.-

Many of the department stores in my area use a large plastic device stapled to the clothing as a security precaution. Several years ago, an adventurous friend of mine got ahold of one of thes somehow, and we took it apart. Inside was a heavy paper strip laminated to aluminum foil (?). As I recall, this paper strip was about half an inch wide and 3-1/2 inces long. When this device got close to a pillar or column at the exits of a store, an alarm would sound. My friend put this paper in his wallet, and we had a lot of fun wandering in and out of various stores at a local shopping center. We would enter when a group of people would enter, or exit with several other shoppers all together.. When we entered a local Sears in the shopping center in the main corrider of the indoor mall, a loud bell rang. A family with kids was just leaving. The nearest clerk ran out the entrance to look at everyone standing around. A plain clothes security guy appeared out of nowhere. Everyone had a good time. The next store we went in was also packed with people and the manager (?) got paranoid when the alarm went off. If you move about discreetly and don't wear a jacket or coat, you can liven up the busiest of stores. But don't go into an empty store with one of these in your wallet. That's a no-no. Could pleas secure a quantity of these paper strips and send them out with your next issue? Or offer them for sale? They can be great fun, especially in a Xmax shopping mob. The one we had came unlaminated and wouldn't work any more. This might be a great money maker for TAP. You may even want to devote an entire issue to this neat gadget. These strips could be left inside candy wrappers and in the bottem of a coke cup and placed near these detector columns or pillars. Put one in a plant near a pillar. The uses and fun could be end- less. A good senior class project would be to freak out ever alarm in every store so equiped, at 2 PM some Saturday afternoon when the mall is really packed.

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

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions

Question

What is Ramayana, who is its creator, why was Ramayana written?

Answered: 1 week ago

Question

To solve by the graphical methods 2x +3y = 9 9x - 8y = 10

Answered: 1 week ago