mercredi 23 septembre 2020

Why is Python is not detecting some strings in the list [duplicate]

I have written this python code. Where if the item in the list is a string, it will remove the item. But is successfully removes some of the string but if a string comes right after another one it does not remove it. I don't understand why it is happening.

Here is the code:

alist = ['hello', 'two','what','now', 23, 5, 55, 'wild']
for i in alist:
    if type(i) == str:
        alist.remove(i)
print(alist)

Aucun commentaire:

Enregistrer un commentaire