3.7k views
1 vote
Implement a function that removes duplicate integers from a list, name the function remove (1st). The function should return a new list, leaving the original list untouched. If the list is empty, an empty list should be returned. For example, remove ([1,2,2,5,5,5,7]) returns [1,2,5,7].

User Kameka
by
7.9k points

1 Answer

4 votes

Final answer:

The function remove_duplicates removes duplicate integers from a list, leaving the original list intact and returns a new list with unique elements only.

Step-by-step explanation:

To remove duplicate integers from a list, the function remove_duplicates can be defined. This function will create a new list with only the unique elements from the original list.

Here is a Python function that accomplishes this task:

def remove_duplicates(lst):
unique_elements = []
for element in lst:
if element not in unique_elements:
unique_elements.append(element)
return unique_elements

If we call remove_duplicates([1,2,2,5,5,5,7]), it will return [1,2,5,7], as expected. The original list will remain unchanged.

User Keen
by
7.2k points