Python 列表中没有出现的单词

Python 列表中没有出现的单词,python,list,Python,List,我有一个任务,我有一个德国歌曲列表,我的输入是歌曲前半部分的一个单词。我们的任务是从歌曲的前半部分中提取一个词,然后看看它是否会再次出现在下半部分,但我们必须以一种特定的方式来做。我们计算单词的长度,跳转到单词2,然后计算单词2的长度,跳转到单词3。。。如果我再次输入原始单词,我将停止输入 我的代码的第一个问题是它总是在列表的末尾,当它到达原始单词输入时它不会停止。第二个问题是,它不会在列表中追加单词2次,只追加一次。循环到达输入或列表末尾后应中断 下面是我认为存在问题的代码:如果歌曲[索引]不

我有一个任务,我有一个德国歌曲列表,我的输入是歌曲前半部分的一个单词。我们的任务是从歌曲的前半部分中提取一个词,然后看看它是否会再次出现在下半部分,但我们必须以一种特定的方式来做。我们计算单词的长度,跳转到单词2,然后计算单词2的长度,跳转到单词3。。。如果我再次输入原始单词,我将停止输入

我的代码的第一个问题是它总是在列表的末尾,当它到达原始单词输入时它不会停止。第二个问题是,它不会在列表中追加单词2次,只追加一次。循环到达输入或列表末尾后应中断

下面是我认为存在问题的代码:如果歌曲[索引]不在查找列表中:

以下是全部代码:

song = ["Es", "gingen", "zwei", "Parallelen",
"ins", "Endlose", "hinaus",
"zwei", "kerzengerade", "Seelen",
"und", "aus", "solidem", "Haus",

"Sie", "wollten", "sich", "nicht", "schneiden",
"bis", "an", "ihr", "seliges", "Grab",
"Das", "war", "nun", "einmal", "der", "beiden",
"geheimer", "Stolz", "und", "Stab",

"Doch", "als", "sie", "zehn", "Lichtjahre",
"gewandert", "neben", "sich", "hin", #End of the first half of the song, index: 42
"da", "wards", "dem", "einsamen", "Paare",
"nicht", "irdisch", "mehr", "zu", "Sinn",

"Warn", "sie", "noch", "Parallelen",
"Sie", "wußtens", "selber", "nicht", 
"sie", "flossen", "nur", "wie", "zwei", "Seelen",
"zusammen", "durch", "ewiges", "Licht",

"Das", "ewige", "Licht", "durchdrang", "sie",
"da", "wurden", "sie", "eins", "in", "ihm",
"die", "Ewigkeit", "verschlang", "sie",
"als", "wie", "zwei", "Seraphim"]


originalWord = input("Enter a word: ")
found_list = [] # The list for found words
index = song.index(originalWord) # Get the index of the first instance of "word"
wordCount = song.count(originalWord)


while True:
    if wordCount <= 1:
        print("Word appears only 1 time and therefore can't appear one more time")
        break  
    try:
        if song[index] not in found_list:
            found_list.append(song[index])
            found_list.append(len(song[index]))
        index += len(song[index]) 
    except: 
        break

print(found_list)

我解决了。我只需要将输入保存在一个变量中,然后比较保存的单词是否在列表中

while True:
if wordCount <= 1:
    print("Word appears only 1 time and therefore can't appear one more time")
    break  
try:
    found_list.append(song[index])
    found_list.append(len(song[index]))
    index += len(song[index]) 
    if song[index] == originalWordSaved:
        found_list.append(song[index])
        found_list.append(len(song[index]))
        print("Theorie works")
        break
except:
    print("Theorie doesn't work") 
    break

从这首歌的前半段中取出一个词,看看它在后半段中的意思是否完全相同?请使用一个较短的示例,并包括一个预期输出。这应该是zwei一词的输出:[zwei',4',hinaus',6',solidem',7',bis',3',seliges',7',beiden',6',als',3',Lichtjahr',10',nicht',5',Warn',4',Sie',3',nicht',5',zwei 4],但输出是相同的,只是结尾没有zwei而已。