Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,038 questions

40,794 answers

573 users

How to find the number of sorted rows in a matrix with Python

1 Answer

0 votes
matrix = [[ 1,  2,   3,  4,  0],
          [ 5,  6, 100,  8,  2],
          [-9, -4,  -3,  2, 71],
          [ 1,  7, 100,  9,  6],
          [ 9, 10,  11, 12, 13]]
          
rows = len(matrix)
cols = len(matrix[0])

count = 0
for i in range(0, rows):
    if (sorted(matrix[i]) == matrix[i]):
        count += 1
        
print("Total sorted rows: " + str(count));



'''
run:

Total sorted rows: 2

'''

 





answered Jun 23, 2023 by avibootz
...