MRAB writes:
I'm wondering whether an alterative could be a function for splicing sequences such as lists and tuples which would avoid the need to create and then destroy intermediate sequences:
splice(alist, i, 1 + 1, [value])
Does this make sense for lists? I don't see how you beat newlist = alist[:] newlist[index_or_slice] = value_or_sequence_respectively (instead of newlist = alist[:i] + [value] + alist[i+1:], which involves creating 4 lists instead of 1). I wonder if it might be reasonable to peephole optimize tmplist = list(atuple) tmplist[index_or_slice] = value_or_sequence_respectively newtuple = tuple(tmplist) Obviously that wouldn't be part of the language, and it would be a PITA for other implementations to mimic for infinitesimal benefit. Steve