def unique(items):
found = set()
keep = []
for item in items:
if item not in found:
found.add(item)
keep.append(item)
return keep
print unique([1, 1, 2, 'a', 'a', 3])
More Related Contents:
- 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)?
- Checking if all elements in a list are unique
- Complexity of list.index(x) in Python
- 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
- How to make a dict from n’th indices of tuples in list
- How do I concatenate items in a list to a single string?
- Why does this iterative list-growing code give IndexError: list assignment index out of range?
- Slicing a list in Python without generating a copy
- Python list doesn’t reflect variable change
- merging Python dictionaries
- Accessing the list while being sorted
- Modifying a list inside a function
- How does the max() function work on list of strings in python?
- How do I sort this list in Python, if my date is in a String?
- Convert all strings in a list to integers
- What is the time complexity of heapq.nlargest?
- Understanding change-making algorithm
- Python Sort One List According to Another List
- counting combinations and permutations efficiently
- deque.popleft() and list.pop(0). Is there performance difference?