In: Computer Science
Python Text processing/masks
Write a function called unique words that takes a phrase as an input string and returns a list of the unique words found in that phrase. The words should be listed in alphabetical order.
Scriipt for ATOM or REPL, NOT PYTHON SHELL
# PLEASE LIKE THE SOLUTION
# FEEL FREE TO DISCUSS IN COMMENT section
# PYTHON PROGRAM
def uniqueWords(inputString):
# now splitt the string according space and find
unique
unique = []
# split
inp = inputString.split(" ")
#nowfor each word if present donot add
for x in inp:
# if x not in list of unique
if x not in unique:
unique.append(x)
# sort in alphabetical order
unique.sort()
return unique;
# main function
def main():
# now call function
# input
inp = "unique ask for unique ask and give ask
result"
result = uniqueWords(inp)
print("Input = "+str(inp))
print("Output = "+str(result))
#PROGRAM EXECUTION STARTS HERE
main()
# SAMPLE OUTPUT