Advertisement
DeaD_EyE

List with __sub__

May 3rd, 2016
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.36 KB | None | 0 0
  1. class List(list):
  2.     def __sub__(self, other):
  3.         try:
  4.             iterator = iter(other)
  5.         except TypeError:
  6.             self.remove(other)
  7.         else:
  8.             for i in iterator:
  9.                 if i not in self: #check for membership
  10.                     raise KeyError
  11.             for i in iter(other):
  12.                 self.remove(i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement