Skip to content

Instantly share code, notes, and snippets.

@jueti
Last active September 16, 2018 08:44
Show Gist options
  • Save jueti/77e3a4a021901285abd4d0cec9bb8261 to your computer and use it in GitHub Desktop.
Save jueti/77e3a4a021901285abd4d0cec9bb8261 to your computer and use it in GitHub Desktop.
[Snippet - useful class]
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
class MyList(list):
def __init__(self, *args):
super(MyList, self).__init__(args)
def __sub__(self, other):
return self.__class__(*[item for item in self if item not in other])
if __name__ == "__main__":
# practice 1
x = MyList(1, 2, 3, 4)
y = MyList(2, 5, 2)
z = x - y
assert z == [1, 3, 4], "assertion failed"
# practice 2
x = [1, 2, 3, 4]
y = [2, 5, 2]
z = MyList(*x) - MyList(*y)
assert z == [1, 3, 4], "assertion failed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment