0

I have a list named wins I want to remove all the elements from wins list using list.remove function but out of 12 elements only six elements are remaining

wins = [[0,0,0,1,0,2,0,3,0,4],[1,0,1,1,1,2,1,3,1,4], [2,0,2,1,2,2,2,3,2,4],
                [3,0,3,1,3,2,3,3,3,4],[4,0,4,1,4,2,4,3,4,4],
                [0,0,1,0,2,0,3,0,4,0], [0,1,1,1,2,1,3,1,4,1], [0,2,1,2,2,2,3,2,4,2],
                [0,3,1,3,2,3,3,3,4,3],[0,4,1,4,2,4,3,4,4,4],
                [0,0,1,1,2,2,3,3,4,4],[4,4,3,3,2,2,1,1,0,0]]
for win in wins:
    wins.remove(win)
print("wins", wins)

Output

wins [[1, 0, 1, 1, 1, 2, 1, 3, 1, 4], [3, 0, 3, 1, 3, 2, 3, 3, 3, 4], [0, 0, 1, 0, 2, 0, 3, 0, 4, 0], [0, 2, 1, 2, 2, 2, 3, 2, 4, 2], [0, 4, 1, 4, 2, 4, 3, 4, 4, 4], [4, 4, 3, 3, 2, 2, 1, 1, 0, 0]]

try

wins = [[0,0,0,1,0,2,0,3,0,4],[1,0,1,1,1,2,1,3,1,4], [2,0,2,1,2,2,2,3,2,4],
                [3,0,3,1,3,2,3,3,3,4],[4,0,4,1,4,2,4,3,4,4],
                [0,0,1,0,2,0,3,0,4,0], [0,1,1,1,2,1,3,1,4,1], [0,2,1,2,2,2,3,2,4,2],
                [0,3,1,3,2,3,3,3,4,3],[0,4,1,4,2,4,3,4,4,4],
                [0,0,1,1,2,2,3,3,4,4],[4,4,3,3,2,2,1,1,0,0]]
for win in wins:
    wins.remove(win)
print("wins", wins)

expecting

wins []

but output

wins [[1, 0, 1, 1, 1, 2, 1, 3, 1, 4], [3, 0, 3, 1, 3, 2, 3, 3, 3, 4], [0, 0, 1, 0, 2, 0, 3, 0, 4, 0], [0, 2, 1, 2, 2, 2, 3, 2, 4, 2], [0, 4, 1, 4, 2, 4, 3, 4, 4, 4], [4, 4, 3, 3, 2, 2, 1, 1, 0, 0]]

  • Did you mean to write: `wins = []`, or `wins.clear()`? Those seem like simpler options for you. – quamrana Jul 22 '23 at 11:15
  • yes, I can use wins. `winsclear()`o clear the list, but I have a condition in which only a few elements will be removed based on the condition . which I didn't mention in the question – SRISANT PATI Jul 22 '23 at 11:20
  • Ok, so its a good job that the duplicate I linked to shows you how to do all that. – quamrana Jul 22 '23 at 11:21

0 Answers0