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 _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/VP7TP5ZEDBMS7LSLYBSQ3IVL2FDSKW2U/ Code of Conduct: http://python.org/psf/codeofconduct/