71. Problem to check elements are unique or not in the given list.

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
  1. Take a list as input.
  2. Check whether all elements are unique or not from the given list using for loop and if statement.
  3. If even one element repeats in the list break the loop.
  4. 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

Remove duplicate dictionaries from a given list

Remove duplicate sublists from the list

Leave a Comment