Use Python’s set intersection:
>>> list1 = [1,2,3,4,5,6]
>>> list2 = [3, 5, 7, 9]
>>> list(set(list1).intersection(list2))
[3, 5]
More Related Contents:
- how to unpack a tuple in this form (‘abc’, [20, 20])? [closed]
- Shuffling a list of objects
- Pandas column of lists, create a row for each list element
- What is the difference between `sorted(list)` vs `list.sort()`?
- What do ellipsis […] mean in a list?
- How can I get list of values from dict?
- Converting a string representation of a list into an actual list object [duplicate]
- How do I merge a list of dicts into a single dict?
- Splitting a list into N parts of approximately equal length
- How to do a recursive sub-folder search and return files in a list?
- List of lists into numpy array
- Replace values in list using Python [duplicate]
- Split a list into parts based on a set of indexes in Python
- Is there a better way to iterate over two lists, getting one element from each list for each iteration? [duplicate]
- How do I iterate through two lists in parallel?
- Python – How to check list monotonicity
- Why does appending to one list also append to all other lists in my list of lists? [duplicate]
- How to return a subset of a list that matches a condition [duplicate]
- Some built-in to pad a list in python
- Remove duplicates and original from list
- Python – sum values in dictionary
- How do I split a string into a list of words?
- Sliding window maximum in O(n) time
- Convert list into a pandas dataframe
- Why do these list methods (append, sort, extend, remove, clear, reverse) return None rather than the resulting list?
- Sorting list according to corresponding values from a parallel list [duplicate]
- Appending to list in Python dictionary [duplicate]
- Does Python have an immutable list?
- Swap values in a tuple/list inside a list in python?
- Nested lambda statements when sorting lists