-1

i want to compare every element of a list and see if there is an element which occurs more than once my code doesn't function, i want to return False if there is one element that occurs more than once, True if all elements are different. i have tried this so far:

def diffElements(liste):
   i = 0
   j = 1
   while i < len(liste):
       if liste[i] == liste[j]:
           return False
       j += 1
       if j == len(liste) - 1:
        print("Jj: " + str(j))
           i += 1
           j = i + 1
abc
  • 1

1 Answers1

4

Use a set to detect duplicates:

def diffElements(liste):
    return len(set(liste)) != len(liste)
quamrana
  • 37,849
  • 12
  • 53
  • 71