Could this be considered a valid mergesort? I tried to do a mergesort function for an assignment without importing merge from heapq:

def mergesort(a):
    if len(a) &lt; 2:
        return a
    return mymerge(mergesort(a[len(a) // 2:]), mergesort(a[:len(a) // 2]))


def mymerge(list1, list2):
    for i in range(len(list1)):
        for x in range(len(list2)):
            if list1[0] &lt; list2[x]:
                list2.insert(x, list1[0])
                list1.pop(0)
                break
            if list1[0] &gt; list2[len(list2) - 1]:
                list2.append(list1[0])
                list1.pop(0)
                break
    return list2


Could this be considered a valid mergesort or does my function have flaws? Are there ways to improve the mymerge function?
No, it is not a merge sort. It never accounts for the fact that list1 is already sorted. Instead it performs len(list1) insertions, every time traversing list2 from the very beginning.

Each call to mymerge is quadratic with respect to the length of the list). At each recursion level \$r\$ there are \$2^r\$ fragments of length \$\dfrac{n}{2^r}\$, so each recursion level will take \$O\left(r\left(\dfrac{n}{2^r}\right)^2\right)\$ time, and summing up for \$r\$ from \$1\$ to \$\log{n}\$ yields the total complexity \$O\left( n^2 \log{n}\right)\$.

The expected runtime of merge sort shall be \$O(n\log{n})\$ (or \$O(n \log^2{n})\$ if done in place).