anonymous
  • anonymous
Hi fellow OCW students, I'm kind of lost on problem 2 of Problem set 9. I still don't get the idea of __iter__(self): Can you guys give me some explanation on what it is and what it does?
MIT 6.00 Intro Computer Science (OCW)
katieb
  • katieb
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this
and thousands of other questions

anonymous
  • anonymous
you are supposed to return an object that will 'yield' the next item when its next method is called. http://docs.python.org/2.7/reference/datamodel.html#special-method-names http://docs.python.org/2.7/reference/datamodel.html#object.__iter__ http://docs.python.org/2.7/library/stdtypes.html#iterator-types http://docs.python.org/2.7/tutorial/classes.html#iterators A google search of - python custom class iterator - returns a number of useful 'hits'
anonymous
  • anonymous
A simple, but clear example from http://johnmc.co/llum/the-easiest-way-to-implement-__iter__-for-a-python-object/ Let's say you write your own class (and it stores a list of vertices and you want to use loop over all vertices using a for loop. How does the for loop know what the next value of your object would be? That's where the __iter__ method comes in. In the __iter__ method, you'll need to say what data is returned when you want to iterate over an object. They can be strings, numbers, anything you want.
anonymous
  • anonymous
Thank you guys!

Looking for something else?

Not the answer you are looking for? Search for more explanations.