-1

I have a vector class that I need to iterate through. The class contains a list variable. I need to iterate through the class.

Im not sure how I would do this. I need to use __iter__ and its suggested that I use yield, here is the result that I want:

[x*2 for x in Vector([3,3.25,"foo"])]
[6, 6.5, 'foofoo']

Iter should return an object that can iterate over the elements of the vector. How would I go about doing this I never used __iter__ before.

Anatoliy Sokolov
  • 347
  • 1
  • 4
  • 10

1 Answers1

1

Basically :

def __iter__(self):
    for elt in self.l:
        yield elt
yoch
  • 343
  • 3
  • 8