def Qalgorithm(index ,all_content):
revert = [] # 所有回复
index_max = len(index)
for i in range(len(index)):
if i + 1 < index_max:
res = index[i], index[i + 1]
result = ''.join(all_content[res[0]:res[1]])
revert.append(result)
else:
result = ''.join(all_content[index[i]:len(all_content)])
revert.append(result)
return revert
if __name__ == '__main__':
all_content = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm']
index = [1, 4, 5, 6, 8, 11] # 问-索引,所在区间便是回复
text = Qalgorithm(index, all_content)
print(text)
网友评论