def _tuple_replace(s, Lindices, Lreplace):
    """
    Replace slices of a string with new substrings.

    Given a list of slice tuples in C{Lindices}, replace each slice
    in C{s} with the corresponding replacement substring from
    C{Lreplace}.

    Example:

     >>> _tuple_replace('0123456789',[(4,5),(6,9)],['abc', 'def'])
     '0123abc5def9'
    """
    ans = []
    Lindices = Lindices[:]
    Lindices.sort()
    if len(Lindices) != len(Lreplace):
        raise ValueError('lists differ in length')
    for i in range(len(Lindices) - 1):
        if Lindices[i][1] > Lindices[i + 1][0]:
            raise ValueError('tuples overlap')
        if Lindices[i][1] < Lindices[i][0]:
            raise ValueError('invalid tuple')
        if min(Lindices[i][0], Lindices[i][1]) < 0 or                    \
           max(Lindices[i][0], Lindices[i][1]) >= len(s):
            raise ValueError('bad index')

    j = 0
    offset = 0
    for i in range(len(Lindices)):

        len1 = Lindices[i][1] - Lindices[i][0]
        len2 = len(Lreplace[i])

        ans.append(s[j:Lindices[i][0] + offset])
        ans.append(Lreplace[i])

        j = Lindices[i][1]
    ans.append(s[j:])
    return ''.join(ans)