A list is a collection of data which can be the same as each other.
There are many methods to remove the duplicates.
The set() method creates a set in Python, which doesn’t accept duplicated entries. Our approach is to use set() to convert a list to a set, then compare the length of original list with the new set.
numbers = [0, 1, 2, 3, 1, 3, 5, 9] numbers_set = set(numbers) if len(numbers) == len(numbers_set): print('No duplicate') else: print('There are ' + str(len(numbers) - len(numbers_set)) + ' duplicates')
any() function takes an iterable (list, string, dictionary etc.) and returns True if any element of the iterable is True. If not, it returns False.
numbers = [7, 2, 5, 2, 1, 5, 5, 8] dup = any(numbers.count(element) > 1 for element in numbers)