iterators

gsm news at contrado.com.au
Thu May 13 07:34:22 EDT 2004


Not too sure but I suppose you can design class iterators and you decide how
they behave.

I normally just add a __iter__ method and use yield

class IteratorObject:

def __init__(self, data):

    self.data = data
    self.__items = len(data)

def __iter__(self):

    index = 0

    while index < self.__items:

        result = blah blah i.e do what ever you want here
        #eg return a random item from list
        yield result
        index += 1

not sure if this helps


"Manlio Perillo" <NOmanlio_perilloSPAM at libero.it> wrote in message
news:o996a0t6ra0pj42emgjpjsr9c375dracrf at 4ax.com...
> Hi.
>
> Python support forward iterators, but what about bidirectional and
> random access ones?
>
>
> Regards   Manlio Perillo





More information about the Python-list mailing list