def test3(): assert_equal(ordinal_form(0), '0th') assert_equal(ordinal_form(1), '1st') assert_equal(ordinal_form(2), '2nd') assert_equal(ordinal_form(3), '3rd') assert_equal(ordinal_form(4), '4th') assert_equal(ordinal_form(5), '5th') assert_equal(ordinal_form(6), '6th') assert_equal(ordinal_form(7), '7th') assert_equal(ordinal_form(8), '8th') assert_equal(ordinal_form(9), '9th')
def get_neighbors(self, n): if n == 1: return self.first_neighbors elif n == 2: return self.second_neighbors elif n == 3: return self.third_neighbors else: return getattr(self, '_{}_neighbors'.format(ordinal_form(n)))
def set_neighbors(self, n, neighbors): if n == 1: self._first_neighbors = neighbors elif n == 2: try: for neighbor in self.first_neighbors: if neighbor in neighbors: neighbors.remove(neighbor) except TypeError: pass self._second_neighbors = neighbors elif n == 3: try: for neighbor in self.first_neighbors: if neighbor in neighbors: neighbors.remove(neighbor) for neighbor in self.second_neighbors: if neighbor in neighbors: neighbors.remove(neighbor) except TypeError: pass self._third_neighbors = neighbors else: try: for neighbor in self.first_neighbors: if neighbor in neighbors: neighbors.remove(neighbor) for neighbor in self.second_neighbors: if neighbor in neighbors: neighbors.remove(neighbor) for neighbor in self.third_neighbors: if neighbor in neighbors: neighbors.remove(neighbor) except TypeError: pass for i in range(4, n): for neighbor in self.get_neighbors(i): if neighbor in neighbors: neighbors.remove(neighbor) setattr(self, '_{}_neighbors'.format(ordinal_form(n)), neighbors)
def test4(): for i in range(100): print(ordinal_form(i))
def get_neighbors(self, n): return [ getattr(atom, '_{}_neighbors'.format(ordinal_form(n))) for atom in self ]
def get_neighbors(self, n): return [getattr(atom, '_{}_neighbors'.format(ordinal_form(n))) for atom in self]