I am not sure if I can make myself clear but will try.
I have a tuple in python which I go through as follows (see code below). While going through it, I maintain a counter (let’s call it ‘n’) and ‘pop’ items that meet a certain condition.
Now of course once I pop the first item, the numbering all goes wrong, how can I do what I want to do more elegantly while removing only certain entries of a tuple on the fly?
JavaScript
x
6
1
for x in tupleX:
2
n=0
3
if (condition):
4
tupleX.pop(n)
5
n=n+1
6
Advertisement
Answer
ok I figured out a crude way of doing it.
I store the “n” value in the for loop when condition is satisfied in a list (lets call it delList) then do the following:
JavaScript
1
3
1
for ii in sorted(delList, reverse=True):
2
tupleX.pop(ii)
3
Any other suggestions are welcome too.