I have a snippet where I need to iterate over a list of items and remove the item whose job is done and continue looping on the remaining items.
as per python I can pass l
to check condition for while
loop as below :-
l = [node1, node2, node3]
while l:
#do something
for t in l:
if t[wt] > 10:
l.remove(t)
but as per this guide, it is not a good practice to modify a list while iterating over it.
So I changed my code to :-
l = [node1, node2, node3]
while len(l)>0:
#do something
for t in l:
if t[wt] > 10:
l.remove(t)
But then I see below pylint warning :-
[pylint] C1801:Do not use len(SEQUENCE) as condition value :- reference
Now what should be the approach here to handle this while
loop with list
which would not violate any of the above practices ?