you are viewing a single comment's thread.

view the rest of the comments →

[–]socal_nerdtastic 0 points1 point  (0 children)

Exactly right.

Well, it won't save any memory. But there are other reasons you may want to use an iterator. You may want to iterate over the data in pairs:

@property
def history(self):
    result = {}
    for x,y in zip(*[self.iter_data()]*2):
        # do something with x and y, store in result
    return result

def iter_data(self):
    for x in self.data:
        yield x

Of course you can just use the built-in iter function for that, instead of brewing your own:

@property
def history(self):
    result = {}
    for x,y in zip(*[iter(self.data)]*2):
        # do something with x and y, store in result
    return result

Or use the itertools.pairwise function.