Program to check all numbers are unique in a sequence.

Last updated 3 years, 2 months ago | 1515 views 75     5

Tags:- Python

You can do this by converting the list to a set using the set() method and comparing the length of this set with the length of the original list. If found equal, return True else False

# function to check unique numbers in the sequence
def check(lst):
 if len(lst) == len(set(lst)):
   return True
 else:
   return False;


print(lst([1,2,3,5]))     
# True

print(lst([1,2,2,3,3,3,5,5,7,8])) 
# False