If you often get an element with a known offset from the previously received element, you need to change .get to return not only the element, but also the position in the list. Then you can implement prevItem as:
def previtem(self, pos): return self.itemlist[pos - 1] item, pos = c.get(itemnum) item2 = c.prevItem(pos)
If instead you perform some operation on item to get a new itemnum , you should save them in a dict instead of list . So get is just a dictionary lookup (much faster than a list lookup):
def get(self, itemnum): return self.premade_dict[itemnum]
So, one way or another, you can replace some searches with cheaper operations.
source share