Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

LoveMathFermat Group Title

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?

  • one year ago
  • one year ago

  • This Question is Closed
  1. bwCA Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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'

    • one year ago
  2. slotema Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    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.

    • one year ago
  3. LoveMathFermat Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Thank you guys!

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.