Paste the list into another list without parentheses and replacing the current item in this index

I am trying to implement the Hierholzers Algorithm in Python to find the Euler loop in a directed graph. Here you can find an example of the algorithm Jeromolets algorithm .

In terms of the example, I just completed the fifth stage, in other words, my algorithm creates a list of levels, where each level represents a tour on the graph.
list_of_levels = [[0, 3, 2, 1, 0], [2, 6, 5, 4, 2], [6, 8, 7, 9, 6]]

To complete the process, I need to combine these lists by inserting each level at the top level to the desired position. For example, the steps for the list above will be,
Step 1 list_of_levels = [[0, 3, 2, 1, 0], [2, 6, 8, 7, 9, 6, 5, 4, 2]]
Step 2list_of_levels = [[0, 3, 2, 6, 8, 7, 9, 6, 5, 4, 2, 1, 0]]

So far I have tried to use the Python insertion method (index, obj), but the result contains the brackets of the inserted list, and also does not replace the element at the index position with the element inserted. The corresponding result with the insertion method for step 1 is as follows.
[2, [6, 8, 7, 9, 6], 6, 5, 4, 2]

So, the question is how to combine these levels without retaining the brackets and not ending with repeating elements (vertices) from other levels.

I am thinking about manually deleting the vertex, wherever I insert the next level, and after I finish from all levels, remove the final list, although for some reason I could not make the chain out of iterable for work.

Even if I manage to implement this solution, I am sure that there is a better alternative.
I would be happy to see some ideas.

+4
3

:

B = [2, 6, 5, 4, 2]
C = [6, 8, 7, 9, 6]
B[1:2] = C
print B

[2, 6, 8, 7, 9, 6, 5, 4, 2]

, 6 6.

:

s [i: j] = t
s j iterable t

+6

:

>>> l = [2, 6, 5, 4, 2]
>>> x = [6, 8, 7, 9, 6]
>>> l = l[:1] + x + l[2:]
[2, 6, 8, 7, 9, 6, 5, 4, 2]
+1

To combine lists, you can use somthing along the lines

>>> lol = [[0, 3, 2, 1, 0], [2, 6, 5, 4, 2], [6, 8, 7, 9, 6]]
>>> trans = {x[0]: x for x in lol[1:]}
>>> combined= lol[0]
>>> while trans:
...     combined = [x for y in comb for x in trans.pop(y, [y])]
...
>>> combined
[0, 3, 2, 6, 8, 7, 9, 6, 5, 4, 2, 1, 0]
0
source

All Articles