Matrix Coding Problems Python