def reset_L_and_R_in_array(edges, lefts):
    """
    Take an array and re-sorts the values in such a way such that:
    - All "D" values remain in the exact same position
    - In the remaining spaces, "L" and "R" are sorted starting from the left with
    all "L"

    Example
    -----------
    Input: [D, R, R, D, L, L, L]
    Output: [D, L, L, D, L, R, R]
    """

    L_count = 0
    for pos, element in enumerate(edges):
        reset_this_entry = element in ("L", "R")
        if reset_this_entry and L_count < lefts:
            edges[pos] = "L"
            L_count += 1
        elif reset_this_entry:
            edges[pos] = "R"
    return edges