HOME/Articles/

python code check list contains unique (snippet)

Article Outline

Python example 'python code check list contains unique'

Functions in program:

  • def unique(list):

python code check list contains unique

Python code example: python code check list contains unique

#Check if a list contains all unique values

def unique(list):
    if len(list)==len(set(list)):
        print("All elements are unique")
    else:
        print("List has duplicates")
unique([1,2,3,4,5])

More Python: https://pythonprogramminglanguage.com