numbers = [1, 2, 3, 4, 5, 3, 2, 1, 6, 7, 8, 5]
unique_numbers = list(set(numbers))
print("List after removing duplicates:", unique_numbers)
#source code --> clcoding.com
Code Explanation:
Define the List with Duplicates:
numbers = [1, 2, 3, 4, 5, 3, 2, 1, 6, 7, 8, 5]
The list numbers contains duplicate values (1, 2, 3, 5 appear multiple times).
Convert List to Set:
unique_numbers = list(set(numbers))
The set(numbers) converts the list into a set, automatically removing duplicates.
Converting it back to a list ensures the output remains in list format.
Print the Unique List:
print("List after removing duplicates:", unique_numbers)
The final output displays the list without duplicates.
0 Comments:
Post a Comment