Answer to Question #335831 in Python for Dhea M. Maddela

Question #335831

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.


1
Expert's answer
2022-04-30T10:21:39-0400
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))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS