write the optimization first, l_children = len(self.children), and avoid creating tuple in the loop just for checking boundaries.