A vector is just a sequence. So you should get the same thing as calling "Vector(['H', 'E', 'L', 'L', 'O'])".
"v1+v2" builds a new vector equal to the sum of v1 and v2 and returns it. The original vectors v1 and v2 are unchanged. "v1+=v2" changes the vector v1 to qual the usm of v1 and v2. v2 remains unchanged.
See previous.
If you're having trouble with something like this (6,8,2)+Vector([4,-3,2]) you probably didn't implement the __radd__ function.
Throw a value error.
Yes.
No.
You can assume that only vectors of equal length will be compared.
Here's a handy example thanks to Valentin Robert:
v = Vector([1, 2, 3]) w = Vector([3, 2, 1]) v > w is False w > v is False v == w is False v >= w is True w <= v is True
>>> Vector([1,2,3,4,5])[3:5] Vector([4, 5])
Instead of super(Vector, self).__lt__(other) try super(Vector, self) < other
See previous.
Did you forget to return a value from the decorated function?
You cannot use lists,dictionaries or any other mutable data type as a key for a python dictionary. You are going to have to figure out a different way to rememer arguments containing dictionaries/lists and the keyword arguments.
You should think carefully what happens to control flow when an exception is thrown? Based on that, think how you need to adjust indentation.
Exceptions are a value like any other, than can be stored, and then thrown again (read the docs on try/catch/raise).
Yes.
@memoized def foo(a,b,c): ... foo(5,3,2) foo(5,c=2,b=3)
In the first case the decorated function would see 5,3,2 as positional arguments, and in the second it would see 5 as a positional argument, and c=2 and b=3 as keyword arguments. So unfortunately, these would be different calls. (i.e. you can't memoize the second, using the result of the first).
Yes. Create a new python script (lets call it foo.py) with the following contents:
from decorators import * run_examples()Then from the command line run "python foo.py > output.txt" and Voila!