0

I just learn python.I have a problem here.It is simple code,But I don't know why the result is unexpected.

here is my code:

a=[1,2,3,4,6,7,'dd','ss','gg','oo',8]

for i in a:
    for b in range(10):
        if i==b:
            a.remove(i)

print a

I want to delete the number in a. I am expecting the result will be a=['dd','ss','gg','00'] but the result is :

[2, 4, 7, 'dd', 'ss', 'gg', 'oo']

I cannot understand why the result is this.

Can anyone help me? Thank you!

newbie11
  • 3
  • 1

1 Answers1

0

Try this remove all integer from list

      a = [x for x in a if not isinstance(x, int)]
Benjamin
  • 2,257
  • 1
  • 15
  • 24