If order is not important and you don’t need to worry about duplicates then you can use set intersection:
>>> a = [1,2,3,4,5]
>>> b = [1,3,5,6]
>>> list(set(a) & set(b))
[1, 3, 5]
More Related Contents:
- create a loop inside a loop in python
- What are the differences between numpy arrays and matrices? Which one should I use?
- How to read a text file into a list or an array with Python
- How to split a string of space separated numbers into integers?
- Working with big data in python and numpy, not enough ram, how to save partial results on disc?
- How to apply a disc shaped mask to a NumPy array?
- How to remove specific elements in a numpy array
- Shuffle an array with python, randomize array item order with python
- Find nearest indices for one array against all values in another array – Python / NumPy
- Get the position of the largest value in a multi-dimensional NumPy array
- Convert a 1D array to a 2D array in numpy
- Using Numpy Vectorize on Functions that Return Vectors
- How to extend an array in-place in Numpy?
- np arrays being immutable – “assignment destination is read-only”
- Numpy individual element access slower than for lists
- How to turn a video into numpy array?
- Can numpy bincount work with 2D arrays?
- How to convert hexadecimal string to bytes in Python?
- Sort invariant for numpy.argsort with multiple dimensions
- Numpy isnan() fails on an array of floats (from pandas dataframe apply)
- Concatenate range arrays given start, stop numbers in a vectorized way – NumPy
- How to pass a 2d array from Python to C?
- Numpy – Replace a number with NaN
- Python: how to store a numpy multidimensional array in PyTables?
- Python list([]) and []
- Python: Elegant and efficient ways to mask a list
- Efficient dot products of large memory-mapped arrays
- Fast string array – Cython
- Optimal method to find the max of sublist items within list
- SWIG/python array inside structure