Not the most efficient, but straight forward and concise:
if len(x) > len(set(x)):
pass # do something
Probably won’t make much of a difference for short lists.
More Related Contents:
- How do you remove duplicates from a list whilst preserving order?
- Removing duplicates in lists
- Permutations between two lists of unequal length
- How to efficiently compare two unordered lists (not sets) in Python?
- Pythonic way to check if a list is sorted or not
- Detecting consecutive integers in a list [duplicate]
- How to efficiently compare two unordered lists (not sets)?
- In Python, what is the fastest algorithm for removing duplicates from a list so that all elements are unique *while preserving order*? [duplicate]
- How do I remove duplicates from a list, while preserving order?
- How to sort and remove duplicates from Python list? [duplicate]
- Complexity of list.index(x) in Python
- Get unique values in List of Lists
- Python: find closest string (from a list) to another string
- Sliding window maximum in O(n) time
- How to split an iterable into two lists with alternating elements
- How can I match up permutations of a long list with a shorter list (according to the length of the shorter list)? [duplicate]
- Python – Removing overlapping lists
- Find non-common elements in lists
- Fastest way to check if a value exists in a list
- Explanation of how nested list comprehension works?
- Interleave multiple lists of the same length in Python
- Weighted random selection with and without replacement
- TypeError: list indices must be integers or slices, not str
- Weighted random sample in python
- How to count the number of words in a sentence, ignoring numbers, punctuation and whitespace?
- Replace list of list with “condensed” list of list while maintaining order
- Move all zeroes to the beginning of a list in Python
- Circular Reference with python lists
- What is the meaning of list[:] in this code? [duplicate]
- Python Weighted Random [duplicate]