Created
February 15, 2014 06:39
-
-
Save rachtsingh/9015412 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class vector(list): | |
pass | |
def wrap(attr): | |
def wrapped(a, b): | |
return vector(map(lambda x, y: getattr(x, attr)(y), a, b)) | |
return wrapped | |
for attr in "__add__ __sub__ __mul__ __div__".split(): | |
setattr(vector, attr, wrap(attr)) | |
# do something similar for radd, rsub, etc. | |
a = vector([1, 2]) | |
b = vector([2, 3]) | |
print(a * b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment