Removing Duplicates from a List

Write a Python lambda function that removes duplicates from a list. Return the list.

Example 1:

Input: [5, 3, 8, 5, 3, 9]

Output: [5, 3, 8, 9]

Example 2:

Input: ['Hello', 'World', 'Hello', 'Python']

Output: ['Hello', 'World', 'Python']

Consider using the Python built-in function set() inside your lambda function.

# Define the lambda function
remove_duplicates = lambda x: list(set(x))

# Test the function
print(remove_duplicates([5, 3, 8, 5, 3, 9])) # Output: [8, 9, 3, 5]
print(remove_duplicates(['Hello', 'World', 'Hello', 'Python'])) # Output: ['World', 'Python', 'Hello']

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!