Write a python 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.
Python code:
#defining unique_words function
def unique_words(phrase):
#creating a list unique to store unique
words
unique=[]
#looping each word in phrase
for i in phrase.split():
#checking if it is not
in unique list
if i not in
unique:
#adding it to unique list
unique.append(i)
#returning the sorted list
return(sorted(unique))
#calling unique_words function and testing for sample phrase
print(unique_words("hi i am rahul i am from india"))
Screenshot:
Output:
Get Answers For Free
Most questions answered within 1 hours.