** 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.
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.
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.
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.
Get Answers For Free
Most questions answered within 1 hours.