Merge elements in list based on given indices

后端 未结 3 541
名媛妹妹
名媛妹妹 2021-01-14 12:30

I want to merge element in the list based on given start and stop index of tuple (non-overlap for tuple). I\'ll leave the indices that don\'t mention as it is. This is my ex

3条回答
  •  爱一瞬间的悲伤
    2021-01-14 13:25

    For the fun of it, because I've been learning Haskell, a recursive solution:

    def recursive(ls, merge):
        if merge == []:
            return ls
        else:
            x, xs = merge[0], merge[1:]
            return ls[:x[0]] + [''.join(ls[x[0]:x[1]])] + recursive(ls, xs)[x[1]:]
    

    Only works if there are no overlapping intervals, however.

提交回复
热议问题