I have created a list where within it I seek to eliminate only the lists whose first value is greater than the second value of it.
I tried creating a second list with the elements to remove but I think it is not the most optimal way.
#y = [] x = [[1, 4], [1, 6], [2, 5], [2, 7], [4, 8], [6, 5], [6, 7], [2, 6], [3, 7], [5, 8], [6, 4], [7, 5]] for i in range(len(x)): if x[i][0] > x[i][1]: print(x[i]) # y.append(x[i]) Is there an optimal way to achieve this?
I want that when printing on screen you get the following:
[[1, 4], [1, 6], [2, 5], [2, 7], [4, 8], [6, 7], [2, 6], [3, 7], [ 5, 8]] Best regards,