def merge(A, B):
    """Merge two sorted lists."""
    C = []
    # Take lesser of two elements
    while A and B:
        if A[0] < B[0]:
            C.append(A.pop(0))
        else:
            C.append(B.pop(0))
    # Grab the rest
    if A:
        C.extend(A)
    elif B:
        C.extend(B)
    return C