我有一个像这样的标记化列表。
文字:['In', 'the', 'process', ',', 'the', 'students', 'learn',....]
和另一个这样的列表。
提示词:['In the process', 'For example',...]
然后,我想通过在第二个列表中查找来连接第一个列表中的元素。预期产出:
['In the process', ',', 'the', 'students', 'learn',....]
我该如何解决这个问题?
答案 0 :(得分:0)
Psuedo算法:
List A = ['In', 'the', 'process', ',', 'the', 'students', 'learn',....]
cueWords = ['In the process', 'For example',...]
Initialize new List B
Intialize variable "temp string"
For all elements in List A:
1. If element != ','
then append element to temp string
2. Else if temp_string == The first element of cueWords
add temp string to new list, List B.
add ',' to new List B
flush temp string
Remove first element from cueWords
3. Else if element == ','
Add each word from temp_string to List B, delimited by spaces
Flush temp_string