0

I need to remove multiple value from list in python based on conditional check given in the loop.

Facing issue: when I tried to remove the value from list by using list.remove('value'), index value getting changed the immediate next value after removal value in the list get skipped in the conditional check from the loop.

Do we have any other way to delete multiple from list in python based on conditonal check.

Programmer
  • 35
  • 7
  • If the only purpose of the loop is to remove certain values, just use list iteration . Otherwise, make a list of indexes to remove, and then remove in reverse – Driftr95 Nov 06 '22 at 11:14
  • If I make list of indexes and remove it means, again wll face same issue right? Which means on deleting the value immediate next index get omitted right? – Programmer Nov 06 '22 at 11:32
  • yes, but if you delete in reverse *from the last index* to delete, the issue is moot, because you'll be heading to the *previous* index – Driftr95 Nov 06 '22 at 17:19
  • so, for example, if you want to delete from indexes 2,7 ,12 and 13, delete 13 first, then, 12, then 7 and at last 2 – Driftr95 Nov 06 '22 at 17:21

0 Answers0