At b[i][j] you try to access the jth element of the ith element. However, b is just an empty list, so the ith element doesn't exist, let alone the jth element of that ith element.
You can fix this by appending the elements to b. But first, a list (row) should be created (appended to b) for each list (row) in a.
The following example makes use of the enumerate function. It returns the index and the element, so if you want you can still do stuff with i and j, but this will prevent you from gaining an IndexError. You can still safely use a[i][j], because the indices are derived from a.
a = [
['a', 'b'],
['c', 'd']
]
b = []
for i, row in enumerate(a): # loop over each list (row) in a
b_row = [] # list (row) which will be added to b
for j, element in enumerate(row): # loop over each element in each list (row) in a
if a[0][0] == 'a': # Not sure why each the first element of a has to be checked each loop # Probably a simplification of the operations.
a[0][0] = 'b'
else:
b_row.append(element) # append the element to the list(row) that will be added to b
b.append(b_row) # When the row is filled, add it to b
print(b)
One last comment: it is not recommended to change a list while looping over it in Python (like in the if statement). It is better to apply those changes to your output list, which is b. If it is jsut a simplification of the processessing, just ignore this remark.
if a[0][0] == 'a'each time in loop? Or is that simplification for us?