Arrange according to the first element of the tuple .
class Solution:
def cutOffTree(self, forest):
M = len(forest)
N = len(forest[0])
trees = []
for i in range(M):
for j in range(N):
if (forest[i][j] > 1):
trees.append((forest[i][j], i, j))
trees.sort()
print(trees)