Steven D'Aprano writes: > On Thu, Mar 17, 2022 at 01:21:24AM +0900, Stephen J. Turnbull wrote: > > > 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?
Let me rephrase that. Given that we have a splice builtin, yes, I'm sure it would be used for lists as well as immutable sequences. But would the list use case add much motivation for adding it? > > I don't see how you beat > > > > newlist = alist[:] > > newlist[index_or_slice] = value_or_sequence_respectively > > We know the advantages of an expression versus a statement (or pair of > statements). In general, yes, but for the uses cases where we want splice(), do we? Most of ~50 cases (many duplicates) I looked at from wfdc's post were assignment statements. I guess some might have been the body of a def replace(tuple, index, value), in which case the calls would have been expressions. But many of them were parts of suites, so the author intended them to be assignments. _______________________________________________ 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/UW5UDDFGFAJ4KIHFCM4M6JTGIHHJFJFX/ Code of Conduct: http://python.org/psf/codeofconduct/