def set_bit(self, i, x):
    """
    Set bit i to x (extending to the right with zeros if needed).
    """
    i = int(i)
    if i >= len(self):
      self.extend([0] * (i + 1 - len(self)))
    self[i] = x

    Set bit i to x (extending to the right with zeros if needed).
    
recipes/Python/440658_Memory_compacted_list_of_bits/recipe-440658.py