I have a rectangular matrix with digits only, i want calculate the number of different unique 2 × 2 square matrices in it.
I stored all possible 2x2 matrices in a new list. Now I want to re move all duplicate matrices from this new list. I don't know how to do it. If I use 'set()' function it gives me the error "unhashable type: 'list' ".
def differentSquares(matrix):
squares_list = []
for i in range (len(matrix)-1):
for j in range (len(matrix[i])-1):
temp=[[matrix[i][j],matrix[i][j+1]],
[matrix[i+1][j],matrix[i+1][j+1]]]
squares_list.append(temp)
return len(squares_list)
I know this problem can be solved by a different logic but I still want to know how can someone remove a duplicate matrix from a list of matrices.
If I enter the following input
Matrix=[[1,2,1],
[2,2,2],
[2,2,2],
[1,2,3],
[2,2,1]]
The value returned is 8 as I returned the length of the list without removing the duplicates. If I remove the duplicates the answer will become 6(correct answer)