Write a function which takes a list of strings as input and returns unique values in the list.
Sample:
>>> unique_list(['cat', 'dog', 'cat', 'bug', 'dog', 'ant', 'dog', 'bug'])
['cat', 'dog', 'bug', 'ant']
My current code:
def unique_list(input_list):
for word in input_list:
if word not in input_list:
output_list = [word]
return output_list
print(output_list)
I get this error(s):
> Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
unique_list(['cat', 'dog', 'cat', 'bug', 'dog', 'ant', 'dog', 'bug'])
File "/Users/****/Desktop/University/CompSci 101/Lab Work/Lab 05/lab05_Homework.py", line 12, in unique_list
print(output_list)
UnboundLocalError: local variable 'output_list' referenced before assignment
What am I doing wrong?
list(set(['cat', 'dog', 'cat']))=> ['cat', 'dog']