Getting previous index values of a python list items after shuffling
<p>Let's say I have such a python list:</p>

<pre><code>l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
</code></pre>

<p>by using <code>random.shuffle</code>, </p>

<pre><code>&gt;&gt;&gt; import random
&gt;&gt;&gt; random.shuffle(l)
&gt;&gt;&gt; l
[5, 3, 2, 0, 8, 7, 9, 6, 4, 1]
</code></pre>

<p>I am having the above list.</p>

<p>How can I get the previous index values list of each item in the shuffled list? </p>

<p>Create a copy of the original <code>list</code> and shuffle the copy:</p>

<pre><code>&gt;&gt;&gt; import random    
&gt;&gt;&gt; l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
&gt;&gt;&gt; l_copy = list(l)  # &lt;-- Creating copy of the list
&gt;&gt;&gt; random.shuffle(l_copy)  # &lt;-- Shuffling the copy
&gt;&gt;&gt; l_copy   # &lt;-- Shuffled copy               
[8, 7, 1, 3, 6, 5, 9, 2, 0, 4]
&gt;&gt;&gt; l   # &lt;-- original list
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
&gt;&gt;&gt; 
</code></pre>

python