Create a Python function that takes a list and returns a new list with unique elements of the first list.
Sample List : [1,2,3,3,3,3,4,5]
Unique List : [1, 2, 3, 4, 5]
I need the code to have an output stated above.
source_list = [int(i) for i in input("Input a numbers list: ").split()]
def unique_list(source_list):
unique = []
for elem in source_list :
if elem not in unique:
unique.append(elem)
return unique
print(unique_list(source_list))
Comments
Leave a comment