Sion Arrowsmith wrote: > clementine <[EMAIL PROTECTED]> wrote: > >Thanx Nick...I forgot to mention im using python 2.2 and along with a host > >of other things it doesnt seem to have the enumarate built in function > >:(:(:(...is it possible to replace it by something else? I dont think > >simulating it will be feasible.... > > Here's one I prepared earlier: > > if sys.version_info < (2,3): > def enumerate(l): > return zip(range(len(l)), l) > > which will suck somewhat on large lists compared to being able to > do it with iterators. >
Iterators are available in python 2.2 class enumerate: def __init__(self, inlist): self.inlist = inlist self.index = 0 def next(self): if self.index >= len(self.inlist): raise StopIteration thisone = self.inlist[self.index] self.index += 1 return self.index-1, thisone def __iter__(self): return self Regards, Fuzzy http://www.voidspace.org.uk/python/index.shtml > -- > \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ > ___ | "Frankly I have no feelings towards penguins one way or the other" > \X/ | -- Arthur C. Clarke > her nu becomež se bera eadward ofdun hlęddre heafdes bęce bump bump bump -- http://mail.python.org/mailman/listinfo/python-list