我对这句话进行了编码:
这是一个了不起的“摘要”,而这是这个惊人的摘要的结尾。
对此:
1 2 3 4“ 5” 6 7:2 8 9 10 7 4 5。
对应的索引表(作为文本文件)为:
word,index
This,1
is,2
an,3
amazing,4
abstract,5
AND,6
this,7
the,8
end,9
of,10
现在我要从这些数字开始:'1 2 3 4“ 5” 6 7:2 8 9 10 7 4 5.'到使用索引表的相应单词。
我使用以下代码以切片列表形式打开索引表文本文件:
index_file = open("decompress.txt","r")
content_index = index_file.read().split()
print(content_index)
输出:
['word,index','This,1','is,2','an,3','amazing,4','abstract,5','AND,6','this,7','the,8','end,9','of,10']
然后我使用以下代码将每个元素切成新列表:
for line in content_index:
fields = line.split(",")
输出:
['word','index']
['This','1']
['is','2']
['an','3']
['amazing','4']
['abstract','5']
['AND','6']
['this','7']
['the','8']
['end','9']
['of','10']
我尝试使用fields [0]和fields [1]和for循环解码数字,但是没有成功。任何帮助将不胜感激!