Your code makes B just a reference to the first element in A This is a problem because the first element in A is a mutable object, namely a list. You want to copy elements A[0] to a new list, which you will name B :
b = a[0][:] # lowercase variable names according to PEP8
Note that this still makes small copies of the elements in A[0] . This will work for your case, since you said that these elements are numeric, which means they are immutable. If, however, you had more nested lists contained in A[0] , or other mutable objects instead of numbers, you might run into the same problem later, at the same level below. Just be careful to pay attention to where you need whole new objects and where there are enough links.
source share