CBSE Class 12 Computer Science
Question 41 of 57
Review of Python Basics — Question 41
Back to all questions 41
Question Write a Python program to get unique values from a list.
input_list = eval(input("Enter the list: "))
unique_values = []
for item in input_list:
if item not in unique_values:
unique_values.append(item)
print("Unique values from the list:", unique_values)Enter the list: [1, 2, 3, 3, 4, 5, 5, 6, 6, 7]
Unique values from the list: [1, 2, 3, 4, 5, 6, 7]
input_list
=
eval
(
input
(
"Enter the list: "
))
unique_values
=
[]
for
item
in
input_list
:
if
item
not
in
unique_values
:
unique_values
.
append
(
item
)
print
(
"Unique values from the list:"
,
unique_values
)
Output
Enter the list: [1, 2, 3, 3, 4, 5, 5, 6, 6, 7]
Unique values from the list: [1, 2, 3, 4, 5, 6, 7]