I think this is a transformation in place;
lst = [1,2,3,4,5,6,7,8,9,10,11] to_exclude = [8,4,11,9] print 'lst == %s\nto_exclude == %s' % (lst,to_exclude) for i in xrange(len(lst)-1,-1,-1): if lst[i] in to_exclude: lst.pop(i) print '\nlst ==',lst
result
lst == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] to_exclude == [8, 4, 11, 9] lst == [1, 2, 3, 5, 6, 7, 10]
eyquem
source share