Using the method and exception list
def method(l, exclude): return [i for i in l if not any(i in x for x in exclude)] r = method(range(100), [range(5,10), range(20,50)]) print r >>> [0, 1, 2, 3, 4, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]
My example uses ranges with int. But this method can be any list of elements with any number of exception lists with other elements if the elements have an equal comparison.
Edit: Faster method:
def method2(l, exclude): ''' l is a list of items, exclude is a list of items, or a list of a list of items exclude the items in exclude from the items in l and return them. ''' if exclude and isinstance(exclude[0], (list, set)): x = set() map(x.add, [i for j in exclude for i in j]) else: x = set(exclude) return [i for i in l if i not in x]