Write a Python program to get unique values from a list


The program creates a list named "l" which contains 10 integers. It then uses the built-in set function to convert the list into a set, which automatically removes any duplicate elements. The set is then converted back into a list using the built-in list function, creating a new list named "new_list" which contains only unique elements from the original list "l". Finally, the program prints the original list and the new unique list.

Source Code

l = [ 82,4,10,56,78,4,34,5,10,9]
print("Original List : ",l)
s = set(l)
new_list = list(s)
print("Unique Numbers : ",new_list)
 

Output

Original List :  [82, 4, 10, 56, 78, 4, 34, 5, 10, 9]
Unique Numbers :  [34, 4, 5, 9, 10, 78, 82, 56]

Example Programs