[Python] pop/remove items out of a python tuple

Discussão em 'Python' iniciado por Stack, Junho 9, 2025.

  1. Stack

    Stack Membro Participativo

    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?

    for x in tupleX:
    n=0
    if (condition):
    tupleX.pop(n)
    n=n+1

    Continue reading...

Compartilhe esta Página