LangWart: Method congestion from mutate multiplicty

Chris Angelico rosuav at gmail.com
Sun Feb 10 08:24:43 EST 2013


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]

Actually, come to think of it, that scores about the same on
readability. Six of one, half dozen of the other.

ChrisA



More information about the Python-list mailing list