- (6 points)
def __le__(self,other):
if self._isEmpty():
return True # empty list is less than or equal to anything
elif other._isEmpty():
return False # cannot otherwise be less than or equal to an empty list
else:
# both lists are non empty; compare the heads
if self._head < other._head:
return True
elif self._head > other._head
return False
else:
# heads are the same; revert to rest
return self._rest <= other._rest
- (6 points)
def index(self, value, start=0):
if self._isEmpty():
raise ValueError('OurList.index(x): x not in list')
elif start == 0 and self._head == value:
return 0
else:
return 1 + self._rest.index(value, max(start-1,0))
- (6 points)
def binary(n):
answer = str(n % 2) # rightmost bit, for now
if n >= 2:
answer = binary(n // 2) + answer
return answer