<s>Human: 给定两个已排序的列表，请编写一个Python函数来合并这两个列表并使其保持排序。
List1: [1, 3, 4, 5] 
List2: [2, 6, 7, 8]
</s><s>Assistant: def merge_lists(list1, list2):
    merged_list = []
    i = 0
    j = 0
    while i < len(list1) and j < len(list2):
        if list1[i] < list2[j]:
            merged_list.append(list1[i])
            i += 1
        else:
            merged_list.append(list2[j])
            j += 1
    while i < len(list1):
        merged_list.append(list1[i])
        i += 1
    while j < len(list2):
        merged_list.append(list2[j])
        j += 1
    return merged_list

list1 = [1, 3, 4, 5]
list2 = [2, 6, 7, 8]
merged_list = merge_lists(list1, list2)
print(merged_list)  # [1, 2, 3, 4, 5, 6, 7, 8]
</s>