问算法

作者: 月夜星空下 | 来源:发表于2022-05-30 16:50 被阅读0次
    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)
    

    相关文章

      网友评论

          本文标题:问算法

          本文链接:https://www.haomeiwen.com/subject/biwoprtx.html