-2

How can i write a program to check that all elements in a list are unique. I have a list that is entered by the user and i would like the program to check that the elements are unique, if they are, say list=[1,2,3,4,5], then the program continues. If not, say list=[1,2,3,4,5,5,5], then the user must reenter the list. Thankyou

1 Answers1

2

This link has explained in details https://www.geeksforgeeks.org/python-check-if-list-contains-all-unique-elements/

# to check all unique list elements 
flag = len(set(test_list)) == len(test_list) 
Hassan
  • 118
  • 6