Python3 TypeError: list indices must be integers or slices, not str
07:36 12 Mar 2016

i have the task to get the String 'AAAABBBCCDAABBB' into a list like this: ['A','B','C','D','A','B']

I am working on this for 2 hours now, and i can't get the solution. This is my code so far:

list = []

string = 'AAAABBBCCDAABBB'

i = 1

for i in string:
    list.append(i)

print(list)

for element in list:
    if list[element] == list[element-1]:
        list.remove(list[element])

print(list)

I am a newbie to programming, and the error "TypeError: list indices must be integers or slices, not str" always shows up...

I already changed the comparison

if list[element] == list[element-1]

to

if list[element] is list[element-1]

But the error stays the same. I already googled a few times, but there were always lists which didn't need the string-format, but i need it (am i right?).

Thank you for helping! NoAbL

string list python-3.x int typeerror