Arshad Mehmood

Search the blog

    Today I Learned

    Check if list contains unique elements

    python

    Python sets are always unique, so we can compare the length of the original list with a list of set of the original list.

    # using set() + len() 
    # to check all unique list elements 
    isListUnique = len(set(test_list)) == len(test_list)