Search code examples
pythonstringlistduplicates

How do I check if there are duplicates in a flat list?


For example, given the list ['one', 'two', 'one'], the algorithm should return True, whereas given ['one', 'two', 'three'] it should return False.


Solution

  • Use set() to remove duplicates if all values are hashable:

    >>> your_list = ['one', 'two', 'one']
    >>> len(your_list) != len(set(your_list))
    True