python 2d array indices must be integers or slices and not tuples

Java newbies here as well, but let’s try translate together:

memArray = [[None], [None]]

is not a Python equivalence for

Object[][] memoryArray = new Object[256][17];

Instead:

memArray = [[None for _ in range(17)] for _ in range(256)]

And

# Java
memoryArray[memoryRow][memoryCol] = " "+Integer.toString(MBR);

translate directly to:

memArray[memR][memC] = " " + str(MBR)

And lastly, while Numpy array might help with advanced indexing over Python’s list, if you are working with strings/objects, you wouldn’t see much improvement in computing efficiency.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top