Python: list index out of range (Assigning a 2D list to another 2D list)
<p>I am processing a 2D list and want to store the processed 2D list in a new 2D list with same indexes. But, I am getting error "list index out of range"</p>

<p>I have simplified my code to make it easy to understand:</p>

<pre><code>a = [
    ['a', 'b'],
    ['c', 'd']
]
print a

b = []
for i in range(len(a)):
    for j in range(len(a[i])):
        if a[0][0] == 'a':
            a[0][0] = 'b'
        else:
            b[i][j] = a[i][j] #list index out of range
</code></pre>

<p>Thanks</p>

<p>I don't have any idea about your expected output. I just fixed the error. 
At first <code>append</code> an empty <code>list</code> to <code>b</code> then you can access <code>b[i]</code> and so on. </p>

<p>Code:</p>

<pre><code>a = [
    ['a', 'b'],
    ['c', 'd']
]
print(a)

b = []
for i in range(len(a)):
    b.append([]) #Append an empty list to `b`
    for j in range(len(a[i])):
        if a[0][0] == 'a':
            a[0][0] = 'b'
        else:
            b[i].append(a[i][j]) #No error now

print(b)
</code></pre>

python arrays list