You can use sets:
main_list = list(set(list_2) - set(list_1))
Output:
>>> list_1=["a", "b", "c", "d", "e"]
>>> list_2=["a", "f", "c", "m"]
>>> set(list_2) - set(list_1)
set(['m', 'f'])
>>> list(set(list_2) - set(list_1))
['m', 'f']
Per @JonClements’ comment, here is a tidier version:
>>> list_1=["a", "b", "c", "d", "e"]
>>> list_2=["a", "f", "c", "m"]
>>> list(set(list_2).difference(list_1))
['m', 'f']
Related Contents:
- What are the advantages of NumPy over regular Python lists?
- Convert NumPy array to Python list
- Python find elements in one list that are not in the other [duplicate]
- List of lists into numpy array
- What is the inverse function of zip in python? [duplicate]
- Filtering a list based on a list of booleans
- Index all *except* one item in python
- How to save a list as numpy array in python?
- Convert 2d numpy array into list of lists [duplicate]
- List to array conversion to use ravel() function
- How to convert list of numpy arrays into single numpy array?
- How to use python numpy.savetxt to write strings and float number to an ASCII file?
- Python Array Slice With Comma?
- ‘list’ object has no attribute ‘shape’
- python pandas flatten a dataframe to a list
- How to create a numpy array of lists?
- How to check if a variable is either a python list, numpy array or pandas series
- Python List of np arrays to array
- numpy-equivalent of list.pop?
- How to access a column in a list of lists in python
- Convert list or numpy array of single element to float in python
- Is there a difference between `board[x, y]` and `board[x][y]` in Python?
- Failed to find data adapter that can handle input: , ( containing values of types {“”})
- concatenate numpy arrays which are elements of a list
- How to make List from Numpy Matrix in Python [duplicate]
- How can the Euclidean distance be calculated with NumPy?
- Flatten an irregular list of lists
- How to split a list based on a condition?
- How do I check which version of NumPy I’m using?
- remove None value from a list without removing the 0 value
- How to smooth a curve in the right way?
- Counting unique values in a column in pandas dataframe like in Qlik?
- How to find all positions of the maximum value in a list?
- numpy.where() detailed, step-by-step explanation / examples [closed]
- Remove all values within one list from another list? [duplicate]
- Standard deviation of a list
- Python: converting a list of dictionaries to json
- Summing elements in a list [duplicate]
- Binary random array with a specific proportion of ones?
- How to count the number of words in a sentence, ignoring numbers, punctuation and whitespace?
- What is the difference between numpy.fft and scipy.fftpack?
- How to split by comma and strip white spaces in Python?
- Find the min/max excluding zeros in a numpy array (or a tuple) in python
- Iterating over Numpy matrix rows to apply a function each?
- Why can’t I suppress numpy warnings
- How to add column to numpy array
- How to group elements in python by n elements [duplicate]
- Getting Second-to-Last Element in List [duplicate]
- Multiply several matrices in numpy
- How to invert a permutation array in numpy