I have this code below. The first print statement prints out:
['c','a','t','d','o','g','r','a','b','b','i','t']
as expected
wlist = ['cat','dog','rabbit']
llist = [letter for word in wlist for letter in word]
tlist = []
print (llist)
for item in llist:
if not item in tlist:
tlist.append(item)
else:
llist.remove(item)
print (llist)
The second one, I expect it to print:
['c','a','t','d','o','g','r','b','i']
But it actually prints:
['c','d','o','g','r','a','b','b','i','t']
I do not understand why. I am trying to take every repeat occurrence of a letter out of llist. But the first occurrence seems to get taken out, and the two b's still remain. Can anyone explain to me how that happened?