Merge two list with some order rule in python
<p>I don't know how to give an accurate title, but here's the problem.</p>

<p>The problem:</p>

<p>I want to give a ranking list (imagine some top list) with some position preserved already.</p>

<p>Say I got 7 slots <code>[1, 2, 3, 4, 5, 6, 7, 8]</code> and some has already preserved postion 1, 3, 4, 7, 9. (As we only have 8 slots, the perserved postion 9 will means the last slot.)</p>

<p>Then I have 2, 5, 6 slots left, which I have to fill them with other objects.</p>

<p>The simplified question:</p>

<p>I have two list:</p>

<pre><code>&gt;&gt;&gt; a = [1, 3, 4, 7, 9]
&gt;&gt;&gt; b = [object_x, object_y, object_z]
</code></pre>

<p>And I want to merge them to this:</p>

<pre><code>&gt;&gt;&gt; c = [1, object_x, 3, 4, object_y, object_z, 7, 9]
</code></pre>

<p>(We can take the 'object_x' here as 0.)</p>

<p>That's it, just want to see if there is an elegant way to implement this.</p>

<p>(Edit whole question based on the comments. Thank you guys very much.)</p>
