Skip to content

Instantly share code, notes, and snippets.

@rachtsingh
Created February 15, 2014 06:39
Show Gist options
  • Save rachtsingh/9015412 to your computer and use it in GitHub Desktop.
Save rachtsingh/9015412 to your computer and use it in GitHub Desktop.
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