Question

** Language Used : Python ** PART 2 : Create a list of unique words This...

** Language Used : Python **

PART 2 : Create a list of unique words

This part of the project involves creating a function that will manage a List of unique strings. The function is passed a string and a list as arguments. It passes a list back.

  1. The function to add a word to a List if word does not exist in the List. If the word does exist in the List, the function does nothing.

  2. Create a test program that takes a string as input and then calls the function over and over until the user enters "Done." If the string "Done" is entered, the program sorts the list and prints it out line by line.

PART 4: Parse a file into a list of unique words

The goal of this part is to create a unique list of only the words in the document and not the other characters.

  1. In this part of the project, each team should read their file into a list and then iterate through the list, line by line, spliting the lines into words in a list. Before splitting the line into parts, the data cleaning function created in Part 1 should be called to remove all unwanted characters from the line.
  2. Then use the function created in Part 2 to to add those words to a list of unique words.
  3. Words should all be converted to uppercase before being addded into the List so that "Green" and "green" are considered the same. Also, any words that begin as all caps or as all numeric should not be added to the list.
  4. Finally, once the entire text is processed, print out the contents of the list line by line. If you notice any characters that should have been removed, go back and add them to your file in Part 3 using the keyboard.
  5. The successful projects will only have words in their output. There will be no special characters or numbers.

Homework Answers

Answer #1

Here is the code,

For Part 2 :

def fun(str, list):
    for word in list:
        if word == str:
            return list
    list.append(str)
    return list

def main():
    list = []
    flag = True;
    while flag:
        str = input("Enter string : ")
        if str == 'Done':
            flag = False
        else:
            list = fun(str, list)
    list.sort()
    for word in list:
        print(word)
        
if __name__=="__main__":
    main()

Output :

Part 4 is incomplete, so please specify part 1 as well to complete it.

I hope you liked the solution, if you have any doubts feel free to ask in comment section and also don't forget to upvote the solution.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Create a program that copies the data from one file to another while converting all lowercase...
Create a program that copies the data from one file to another while converting all lowercase vowels to uppercase vowels. Your program should accept two arguments: an input file to read from and an output file to copy to. • Your program should check to make sure the output file does not already exist. If it does, print "DESTINATION FILE EXISTS." to stdout. • Print the number of characters changed to stdout using the format string "%d characters changed." •...
2. Define a function write_to_file(filename, text) that takes in a filename (a string) and a list...
2. Define a function write_to_file(filename, text) that takes in a filename (a string) and a list of strings as arguments. Your function will open a file and write the contents of text onto the file. Each element in the list represents a separate line in the file, without newline characters. You will have to add the newline characters in yourself. This function does not return or print anything; it will create a new file.
Create a Python program that: Allows the user to enter a phrase or sentence. The program...
Create a Python program that: Allows the user to enter a phrase or sentence. The program should then take the phrase or sentence entered Separate out the individual words entered Each individual word should then be added to a list After all of the words have been place in a list Sort the contents of the list Display the contents of the sorted list with each individual word displayed on a separate line Display a message to the user indicating...
Please create a python module named homework.py and implement the functions outlined below. Below you will...
Please create a python module named homework.py and implement the functions outlined below. Below you will find an explanation for each function you need to implement. When you are done please upload the file homework.py to Grader Than. Please get started as soon as possible on this assignment. This assignment has many problems, it may take you longer than normal to complete this assignment. This assignment is supposed to test you on your understanding of reading and writing to a...
Using python 3.5 or later, write the following program. A kidnapper kidnaps Baron Barton and writes...
Using python 3.5 or later, write the following program. A kidnapper kidnaps Baron Barton and writes a ransom note. It is not wrriten by hand to avoid having his hand writing being recognized, so the kid napper uses a magazine to create a ransom note. We need to find out, given the ransom note string and magazine string, is it possible to given ransom note. The kidnapper can use individual characters of words. Here is how your program should work...
Program Behavior Each time your program is run, it will prompt the user to enter the...
Program Behavior Each time your program is run, it will prompt the user to enter the name of an input file to analyze. It will then read and analyze the contents of the input file, then print the results. Here is a sample run of the program. User input is shown in red. Let's analyze some text! Enter file name: sample.txt Number of lines: 21 Number of words: 184 Number of long words: 49 Number of sentences: 14 Number of...
python program 1. create a .txt file and call it fruits.txt, add the following items to...
python program 1. create a .txt file and call it fruits.txt, add the following items to the file Apple Banana Peach Strawberry Watermelon Kiwi Grape 2. Write a program that does the following: - Reads the fruit.txt - Converts the contents into all uppercase - Writes the uppercased values into a text file called "UpperFruit.txt" OUTPUT SHOULD BE: APPLE BANANA PEACH STRAWBERRY WATERMELON KIWI GRAPE
Develop a C++ PROGRAM which will find a hidden sentence in a list of random words...
Develop a C++ PROGRAM which will find a hidden sentence in a list of random words using map function Open this text file named shuffled_words.txt in your program If it matters, you may presume there are an even number of words in the file Place the contents of the file into an appropriate data structure in the following manner: Grab a pair of strings from the file (unless end of file is reached) Each string is separated by a space...
PYTHON : Create a Email Address Parser (* Please do make comments*) Often times, you may...
PYTHON : Create a Email Address Parser (* Please do make comments*) Often times, you may be given a list of raw email addresses and be asked to generate meaningful information from such a list. This project involves parsing such a list and generating names and summary information from that list. The script, eparser.py, should: Open the file specified as the first argument to the script (see below) Read the file one line at a time (i.e., for line in...
Create a function in MIPS using MARS to determine whether a user input string is a...
Create a function in MIPS using MARS to determine whether a user input string is a palindrome or not. Assume that the function is not part of the same program that is calling it. This means it would not have access to your .data segment in the function, so you need to send and receive information from the function itself. The program should be as simple as possible while still using necessary procedures. Follow the instructions below carefully. Instructions: ●...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT