LangWart: Method congestion from mutate multiplicty
steve+comp.lang.python at pearwood.info
Sun Feb 10 15:00:28 CET 2013
Chris Angelico wrote:
> On Sun, Feb 10, 2013 at 10:29 PM, Steven D'Aprano
> <steve+comp.lang.python at pearwood.info> wrote:
>> "inserted" is called addition, together with list slicing when needed.
>> newlist = [item_to_insert] + oldlist
>> newlist = oldlist[0:5] + [item_to_insert] + oldlist[5:]
> Really? Wouldn't it be easier to use slice assignment on a copy?
> newlist = oldlist[:]; newlist[pos:pos] = [item_to_insert]
I don't know about "easier", but it's two statements rather than a single
expression, which means you cannot easily include it as part of a larger
> Actually, come to think of it, that scores about the same on
> readability. Six of one, half dozen of the other.
More information about the Python-list