I am wondering why this piece of code:
wordlist = ['cat','dog','rabbit']
letterlist=[]
for aword in wordlist:
for aletter in aword:
if aletter not in letterlist:
letterlist.append(aletter)
print(letterlist)
prints ['c', 'a', 't', 'd', 'o', 'g', 'r', 'b', 'i']
while this code:
wordlist = ['cat','dog','rabbit']
letterlist=[]
for aword in wordlist:
for aletter in aword:
letterlist.append(aletter)
print(letterlist)
prints ['c', 'a', 't', 'd', 'o', 'g', 'r', 'a', 'b', 'b', 'i', 't']
I don't understand how the code is being computed and doesn't spell out all of 'rabbit' and/or why it spells out 'r', 'b', 'i'? Anyone know what's going on?