def padded_insert(items, index, value, null_val=None):
  """
  insert value into the items list at given index
  if index is larger than length of list then
  extend it up to index and pad the extra space with null_val
  """
  if len(items) == index:
    items.append(value)
  elif len(items) > index:
    items[index] = value
  else:
    items.extend([null_val] * (index - len(items)))
    items.append(value)
  return items