0

I wanted to remove rows in a matrix which has a length less than a certain length without using pandas or numpy or any other libraries.

I have written the following code which I think should remove the rows, but it's not happening. Please suggest a better solution.

mat = [[1,2,3],[4,6],[7,8,9],[1,2,3,4,5,6]]

for x in mat:
    if len(x) < 5 :
        mat.remove(x)

print(mat)

Output :

[[4, 6], [1, 2, 3, 4, 5, 6]]

Expected Output :

[[1, 2, 3, 4, 5, 6]]
noswear
  • 311
  • 1
  • 6
  • 27

0 Answers0