0
給定一個我想要做的短語列表,從列表中獲得一個結構(向量列表)中的字符串,其中第一個位置是字符串:循環插入到python中的向量列表中
sentence_list = ['I want this',' It hurts','Life is too short as it is' ]
structure = [(1,'I want this. Not that. Right now.'), (2,'When I think about what you are doing, I wonder if you realize the effect you are having on me. It hurts. A lot.'),(3,'Life is too short as it is. In short, she had a cushion job.')]
結果將是一個列表,其中包含向量位置0的值。
我第一次嘗試:
result = []
for s in sentence_list:
for i in structure:
if s in i[1].split('.'):
result.append(i[0])
的目標是提高它的方式做一個簡單的線條。
result
[1, 2, 3] # the result is giving the first value of the vector if the string is there..
那麼你的問題到底是什麼? –
我在隔離過程中使用此功能,它工作正常,但我想以更短的方式改善它。 – PeCaDe
首先,你不需要'split' –