CSE 130 - Programming Assignment #6 FAQ

  1. I'm getting Indentation errors, but my indentation looks fine?

  2. The python interpreter differentiates between spaces and TAB-s. So even though two lines may look like they are indented the same width, if one is done with spaces, and the other with TAB-s python will complain. Make sure to be consistent and only use one or the other. One way to get your code to consistently use spaces, is to open it in vim and run the command ":retab"

  3. Can I import other libraries than what already is there?

  4. No. You may only use the imporated libraries and the built-in functions .

  5. For 1a) can we assume the list is sorted?

  6. No.

  7. For 1a) can numbers be negative?

  8. Yes.

  9. For 1b) can lists be of different length?

  10. No. You can assume lists are of equal length.

  11. What if in 1b) we have repeating keys?

  12. Assign the value corresponding to the last occurance of the key.

  13. 2a) What happens when I call "Vector("HELLO")?"

  14. A vector is just a sequence. So you should get the same thing as calling "Vector(['H', 'E', 'L', 'L', 'O'])".

  15. 2c) What is the difference between + and += ?

  16. "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.

  17. 2c) Does + change the two original vectors?

  18. See previous.

  19. 2c) I'm having trouble adding a tuple and a vector (but the reverse order works!)?

  20. If you're having trouble with something like this (6,8,2)+Vector([4,-3,2]) you probably didn't implement the __radd__ function.

  21. 2c) What happens when we pass vectors of different length to +/+=?

  22. Throw a value error.

  23. 2d) For the dot product, if the argument and current Vector instance are not the same length should that raise an exception?

  24. Yes.

  25. 2g) Can I do "Vector([1,2,3]) < [0,0,0]"?

  26. No.

  27. 2g) What happens when we compare vectors of different length?

  28. You can assume that only vectors of equal length will be compared.

  29. 2g) I'm confused by the comparison between vectors?

  30. 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
    

  31. 2f) What type do we return when we get a slice from a Vector?

  32. >>> Vector([1,2,3,4,5])[3:5]
    Vector([4, 5])
    

  33. 2f) Getting an exception when trying to call __lt__/__gt__ ... on an object()(e.g. super(Vector, self).__lt__(other))

  34. Instead of super(Vector, self).__lt__(other) try super(Vector, self) < other

  35. 2f) How do I treat vectors as objects when comparing them?

  36. See previous.