Remove Duplicates from List

Given a list of integers, write a Python program to remove all duplicate elements and return the list in any order.

Example 1:

Input: [1,2,2,3,4,4,5,6,6,7,8,8] 
Output: [1,2,3,4,5,6,7,8]

Example 2:

Input: [10,10,15,15,20,20] 
Output: [10,15,20]

Python’s set data structure does not allow duplicates. You can convert the list into a set and then back to a list.

def remove_duplicates(nums):
    return list(set(nums))

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!