jeudi 28 janvier 2021

why is .remove() method inside 'looped if statement' removing the next element from the list instead of what was tested with if statement [duplicate]

i wanted this command to remove the item i.e. 'copy' from the list. But it removes the next element i.e. 'pen'.

listblock=["ball","copy","pen","paper","bat"]
    
    for item in listblock:
        if item == "copy":
        listblock.remove(item)
    

Aucun commentaire:

Enregistrer un commentaire