Q:

Interpreter is showing "list indices must be integers, not str" error

I'm learning Python. I have combined  numbers and letters in one list. Next I wanted to choose only numbers and append them to another list. When the program encounters letters it gives me this error: 

if not str(a[x]).isalpha(): TypeError: list indices must be integers,
  not str

a = []
b = 'This is a dog'
d = [888, 999]
c = []

for i in range(10):
    a.append(i)

a.extend(b)
for elem in d:
    a.append(elem)

print(a)
print('---------------------------------')
for x in a:
    if not str(a[x]).isalpha():
        c.append(a[x])
        print(c)
    else:
        pass

print(c)

I will appreciate if you can teach me in this case.

A:

print('---------------------------------')
for x in a: # Here you'll get each value of a in x.
    if not str(x).isalpha(): # So here you don't have to use a[x] but simply x.
        c.append(x)
        print(c)
    else:
        pass

What you are doing fails because at some point in x you have "This is a dog".
Asking for a[x] then means asking python to look for "this is a dog" as an index in a.
This fails and python tells you that lists only have integer indices, not strings.

