Is there a way to append/extend a list with another list at a specific index in python? -


In other words, I want to complete something like the following:

  a = [1, 2, 3, 7, 8] B = [4, 5, 6] # There is a list on index 3 to include List B in some magic lists so that one = [1, 2, 3, 4, 5, 6, 7, 8]  

you type a Only:

  & gt; & Gt; & Gt; A = [1, 2, 3, 7, 8] & gt; & Gt; & Gt; B = [4, 5, 6]> gt; & Gt; & Gt; A [3: 3] = B & gt; & Gt; & Gt; A [1, 2, 3, 4, 5, 6, 7, 8] & gt; & Gt; & Gt;   

[3: 3] may seem strange, but it is necessary to enter the item b in the list one < / Code> Otherwise, if we are assigned an index of a , list b , then it will be inserted:

  & Gt; & Gt; & Gt; A = [1, 2, 3, 7, 8] & gt; & Gt; & Gt; B = [4, 5, 6]> gt; & Gt; & Gt; A [3] = B & gt; & Gt; & Gt; A [1, 2, 3, [4, 5, 6], 8]> gt; & Gt; & Gt;  

I tried to find a docs link that explicitly mentions this behavior, but fail (if you can find it, feel free to add one Please). So, I would just say that a [3: 3] = b tells the dragon to move the list to the item b and put it in the list section is represented by a by [3: 3] . In addition, the dragon will expand the list of a needed to adjust this operation.

In short, this is just another awesome feature of Python. :)


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -