def merge(list1,list2):
    """
    Takes two lists and merge them in a sorted list
    """
    # Initialie the empty list
    result=[]
    i=0
    j=0
    # This loop runs till both input lists have non-zero elements in them
    # That means this loop stops when either of the input list runs out of element
    while (len(list1)>0 and len(list2)>0):
        if list1[0]<=list2[0]:
            # Append to the result list
            result.append(list1[0])
            #print("Result:",result)
            # Pop the first element of the list
            list1.pop(0)
            i=i+1
        else:
            # Append to the result list
            result.append(list2[0])
            #print("Result:",result)
            # Pop the first element of the list
            list2.pop(0)
            j+=1
    # Now checking which input list has run out of element.
    # Whichever list still has element left, append all of them to the result array
    # Note, only one of these if-loops will be executed
    if(len(list1)>0):
        result=result+list1
    if(len(list2)>0):
        result=result+list2
    
    #print(f"i:{i},j:{j}")
    return (result)