def checkIndex(key):
if key < 0: raise IndexError
if not isinstance(key, (int , long)): raise TypeError
class NumberQueue:
def __init__(self, start=0, step=1):
self.start = start
self.step = step
self.change = {}
def __getitem__(self, key):
checkIndex(key)
try: return self.change[key]
except:
return self.start + key * self.step
def __setitem__(self, key, value):
checkIndex(key)
self.change[key] = value
nq1 = NumberQueue(1,1)
print nq1[4]
nq1[4]=2
print nq1[4]
if key < 0: raise IndexError
if not isinstance(key, (int , long)): raise TypeError
class NumberQueue:
def __init__(self, start=0, step=1):
self.start = start
self.step = step
self.change = {}
def __getitem__(self, key):
checkIndex(key)
try: return self.change[key]
except:
return self.start + key * self.step
def __setitem__(self, key, value):
checkIndex(key)
self.change[key] = value
nq1 = NumberQueue(1,1)
print nq1[4]
nq1[4]=2
print nq1[4]