Daniel Roy Greenfeld

Daniel Roy Greenfeld

About | Articles | Books | Jobs | News | Tags

Required methods to make a class iterable

This was originally posted on blogger here.

Really useful:

#required iterable elements
class MyIterator(object):

    def iter(self):
        return self.data.iter()

    def len(self):
        return len(self.data)

    def contains(self, v):
        return v in self.data

    def getitem(self, v):
        return self.data[v]

Tags: legacy-blogger
← Back to home