On Sun, Feb 10, 2013 at 10:29 PM, Steven D'Aprano
<steve+comp.lang.pyt...@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
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to