Python - checking whether a list contains duplicates
Did you know?
As long as the elements are hashable, you can check whether a list contains duplicated values by converting it to a set and comparing the lengths of the list and set.
Example:
names = ["Jan", "John", "Marry", "Daisy", "Jan"] names_has_duplicates = len(set(names)) < len(names) print(names_has_duplicates) # => True