If the order does not matter, you can simply calculate the set difference:
>>> set([1,2,3,4]) - set([2,5])
set([1, 4, 3])
>>> set([2,5]) - set([1,2,3,4])
set([5])
More Related Contents:
- Append cumulative list of lists python
- How to find all occurrences of an element in a list
- How to check if a string is a substring of items in a list of strings?
- How to split a list based on a condition?
- Finding max value in the second column of a nested list?
- Why does foo.append(bar) affect all elements in a list of lists?
- list to dictionary conversion with multiple values per key?
- How to get the nth element of a python list or a default if not available
- Python – TypeError: ‘int’ object is not iterable
- How do I split a string into a list?
- Why doesn’t list have safe “get” method like dictionary?
- Explicitly select items from a list or tuple
- How do I prepend to a short python list?
- Python: why does my list change when I’m not actually changing it?
- Does python have a sorted list?
- Summing elements in a list
- “unstack” a pandas column containing lists into multiple rows [duplicate]
- Break string into list of characters in Python [duplicate]
- How to make a custom object iterable?
- Getting a default value on index out of range in Python [duplicate]
- How to access the elements of a 2D array?
- Why does a for-loop with pop-method (or del statement) not iterate over all list elements [duplicate]
- How to create a list of objects?
- List of Tuples to DataFrame Conversion [duplicate]
- Why does using multiplication operator on list create list of pointers? [duplicate]
- Remove dictionary from list
- Determine if 2 lists have the same elements, regardless of order? [duplicate]
- Iterate through adjacent pairs of items in a Python list [duplicate]
- Python The appended element in the list changes as its original variable changes
- sys.getsizeof(list) returns less than the sum of its elements