In this Python list program, we will take a user input as a list and check if the elements are unique or not in the given list with the help of the below-given steps.
List elements are unique:
Steps to solve the program
- Take a list as input.
- Check whether all elements are unique or not from the given list using for loop and if statement.
- If even one element repeats in the list break the loop.
- If they are unique print True otherwise False.
#Input list
list1 = [2, 5, 6, 7, 4, 11, 2, 4, 66, 21, 22, 3]
for i in range(len(list1)):
if list1[i] not in list1[i+1:]:
print("True")
break
else:
print("False")
break
list1 = [2, 5, 8, 3, 6, 21]
for i in range(len(list1)):
if list1[i] not in list1[i+1:]:
print("True")
break
else:
print("False")
break
Output :
False
True
Related Articles
Python program to remove duplicate sublists from the list.
Python program to create a list by taking an alternate item from the list.
Python program to remove duplicate tuples from the list.
Python program to insert an element before each element of a list.
Python program to remove the duplicate string from the list.
Python program to get the factorial of each item in the list.