def isOdd(integer): #assert isinstance(integer, int) return integer % 2 == 1 def isEven(integer): #assert isinstance(integer, int) return integer % 2 == 0 def _list_to_string(li): return ''.join(map(str, li)) class GrayCode(object): def __init__(self, nbits): self._nbits = nbits self._grayCode = [] self.__generate() def __getitem__(self, i): return self._grayCode[i] def __str__(self): return str(self._grayCode) __repr__ = __str__ def __iter__(self): return self._grayCode.__iter__() def __generate(self): li = [0 for i in xrange(self._nbits)] self._grayCode.append(_list_to_string(li)) for term in xrange(2, (1<