iterator pattern def getiterator(self)return mylistiterator(selfif __name__ ="__main__"my_list mylist( my_iterator my_list getiterator(while my_iterator has_next()print(my_iterator next()this prints out the following result this idea of traversing some collection is so widespread that it has name--the iterator pattern ython internal implementation of the iterator pattern as you have probably guessed by nowpython makes implementing the iterator pattern extremely simple in factyou have used iterators already in this book the way for loops are implemented in python uses the iterator pattern takefor instancethis for loopfor in range( )print(ithis is analogous to the iterator pattern implementation we saw in the previous section this convenience in python is accomplished by defining an iterator protocol that is used to create objects that are iterable and then returning some object that knows how to iterate over these iterable objects