我想知道为什么这段代码:
wordlist = ['cat','dog','rabbit']
letterlist=[]
for aword in wordlist:
for aletter in aword:
if aletter not in letterlist:
letterlist.append(aletter)
print(letterlist)
打印 ['c', 'a', 't', 'd', 'o', 'g', 'r', 'b', 'i']
而这段代码:
wordlist = ['cat','dog','rabbit']
letterlist=[]
for aword in wordlist:
for aletter in aword:
letterlist.append(aletter)
print(letterlist)
打印 ['c', 'a', 't', 'd', 'o', 'g', 'r', 'a', 'b', 'b', 'i', 't']
我不明白代码是如何计算的,也没有拼出所有的“兔子”和/或为什么它拼出“r”、“b”、“i”?有谁知道发生了什么?