import exceptions cdef class duplicate_content_class: inorder = True cdef object values cdef int length def __init__(self, *tupl): self.values = list(tupl) self.length = len(self.values) def __cmp__(self, other): left = self.get() if isinstance(other, duplicate_content_class): right = other.get() else: right = other if self.inorder: if left < right: return -1 elif left > right: return 1 else: if left > right: return -1 elif left < right: return 1 return 0 def add(self, x): self.values.append(x) self.length += 1 def get(self): if self.values: return self.values[-1] else: raise exceptions.LookupError def get_all(self): if self.values: return self.values else: raise exceptions.LookupError def delete(self): if self.values: del self.values[-1] self.length -= 1 else: raise exceptions.LookupError def delete_all(self): self.values = [] self.length = 0 # def __iter__(self): # for value in self.values: # yield value def __len__(self): return self.length def __bool__(self): if self.values: return True else: return False