當我嘗試將元組列表添加到另一個列表時,它變爲空。當我將元組列表添加到另一個列表時,它變爲空
tagged_sentences_list = []
for i in range (len(sentences)):
length_sentences = len(sentences[i].split(" "))
del words_in_the_sentence[:]
del tagged_words[:]
for j in range (length_sentences):
length_words_in_sentence = len(sentences[i].split(" ")[j].split("/")[1:])
part_of_the_speech = sentences[i].split(" ")[j].split("/")[1:]
word = sentences[i].split(" ")[j].split("/")[:1]
words_in_the_sentence.append(word)
zipped = zip(word,part_of_the_speech)
tagged_words.append(zipped)
tagged_sentences_list.append(tagged_words)
正是在這一行:
tagged_sentences_list.append(tagged_words)
終端打印
[[]]
我要追加的元組列表到另一個列表。所以我會:
[[(a,b),(c,d)], [(d,e)]]
你們中的任何人有任何想法爲什麼?由於
'德爾tagged_words [:]'你刪除引用。你必須使用'copy'來創建新的列表。 – Brobin