Question

In: Computer Science

Write a function in Python which removes a set of common words from a long piece...

  1. Write a function in Python which removes a set of common words from a long piece of text. Be sure to strip out any punctuation. The common words to be removed are:

a, an, as, at, by, for, in, is, it, of, that, this, to, was, will, the

These are typical words that are considered to have low semantic value.

Process each paragraph provided below individually. Your end result for each paragraph should be a string or list containing the processed paragraph with the common words and punctuation removed. It is not required to put the text samples into a file (you can simply copy and paste into a string variable inside your Python script).

For the text samples to process, use the following (taken from the official Python tutorial):

If you do much work on computers, eventually you find that there’s some task you’d like to automate. For example, you may wish to perform a search-and-replace over a large number of text files, or rename and rearrange a bunch of photo files in a complicated way. Perhaps you’d like to write a small custom database, or a specialized GUI application, or a simple game.

If you’re a professional software developer, you may have to work with several C/C++/Java libraries but find the usual write/compile/test/re-compile cycle is too slow. Perhaps you’re writing a test suite for such a library and find writing the testing code a tedious task. Or maybe you’ve written a program that could use an extension language, and you don’t want to design and implement a whole new language for your application.

Solutions

Expert Solution

Code

str=input()
#punctuations list
p = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
#list of words to be removed
l= [' a ',' an ',' as ',' at ',' by ',' for ',' in ', ' is ',' it ',' of ',' that ',' this ',' to ',' was ',' will ',' the ']
r=""
for i in str:
        if i not in l and i not in p:
                r+=i
print(r)

Terminal Work

.


Related Solutions

17. Write a function in Python which removes a set of common words from a long...
17. Write a function in Python which removes a set of common words from a long piece of text. Be sure to strip out any punctuation. The common words to be removed are: ​​a, an, as, at, by, for, in, is, it, of, that, this, to, was, will, the These are typical words which are considered to have low semantic value. Process each paragraph provided below individually. Your end result for each paragraph should be a string or list containing...
Write a function in Python to take in a piece of sample text via a long...
Write a function in Python to take in a piece of sample text via a long string (you pick the string) and to output a dictionary with each word as a key and it’s frequency (the number of times it occurred in the original string) as the value. Show an example of your function in use. Be sure to strip out any punctuation.
Using Python programming language, write a LONG piece of code that utilizes the do while function...
Using Python programming language, write a LONG piece of code that utilizes the do while function and the switch statement, please do not make It short, thank you.
Write a function that removes all even numbers from an array. The function should take the...
Write a function that removes all even numbers from an array. The function should take the array, length of the array, and a pointer for number of odd numbers found as arguments and return a pointer to the new array. If there are no odd numbers found in the array, your code should print "No odds found." and return NULL. Use the function header: int *removeEvens(int *a, int length, int *oddsFound); Example: Input array a[ ] = {3, 4, 5,...
** * Write a recursive function that removes the first k even numbers * from the...
** * Write a recursive function that removes the first k even numbers * from the stack. If there are less than k even elements in the stack, * just remove all even elements. Do not use any loops or data structures * other than the stack passed in as a parameter. * @param stack * @param k * @return Returns the number of elements removed from the stack. */ public static int removeEvenNumbers(Stack<Integer> stack, int k) { return 0;...
Write a Python program which takes a set of positive numbers from the input and returns...
Write a Python program which takes a set of positive numbers from the input and returns the sum of the prime numbers in the given set. The sequence will be ended with a negative number.
USE PYTHON : # Problem Set 04: - Write a function to seek for all even...
USE PYTHON : # Problem Set 04: - Write a function to seek for all even numbers and odd numbers in the middle of two number A and B. Print even and odd numbers in 1 and 2020 (including both these two numbers) # Problem Set 05: - A website requests an user to input his account password. - Write a program to examize the validity of the password. - The valid password must consists of: - At least 1...
Write a python program function to check the frequency of the words in text files. Make...
Write a python program function to check the frequency of the words in text files. Make sure to remove any punctuation and convert all words to lower case. If my text file is like this: Hello, This is Python Program? thAt chEcks% THE freQuency of the words! When is printed it should look like this: hello 1 this 1 is 1 python 1 program 1 that 1 checks 1 the 2 frequency 1 of 1 words 1
python Write a function pack_to_5(words) that takes a list of string objects as a parameter and...
python Write a function pack_to_5(words) that takes a list of string objects as a parameter and returns a new list containing each string in the title-case version. Any strings that have less than 5 characters needs to be expanded with the appropriate number of space characters to make them exactly 5 characters long. For example, consider the following list: words = ['Right', 'SAID', 'jO'] The new list would be: ['Right', 'Said ', 'Jo '] Since the second element only contains...
Write a Python function ???????? that takes in a nonnegative semiprime number ? which is the...
Write a Python function ???????? that takes in a nonnegative semiprime number ? which is the product of two prime numbers ? and ? and returns the tuple ( ?, ? ) where ?≤? . Example: ????????(22)=(2,11) Example: ????????(3605282209)=(59447,60647) This problem has a time-out limit of 1 second and a memory limit of 1MB. The number ? in all test-cases will satisfy 4≤?≤800000000000000 For example: Test Result print(factorMe(22)) (2, 11) print(factorMe(3605282209)) (59447, 60647)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT