I am given a list l and I want to do assignment:
l
l[index] = val
But there might be a case when the list is too small.
Perhaps this does what you want:
def resize(l, newsize, filling=None): if newsize > len(l): l.extend([filling for x in xrange(len(l), newsize)]) else: del l[newsize:]