Intersection of two arrays
Python-specific questions are probably off-topic here, but this question can be seen as a language-agnostic algorithmic task: given two arrays $A$ and $B$, each representing a multi-set, return an array containing the elements in the multiset $C = A \cap B$.
Here an element $x$ that has multiplicity $a$ in $A$ and $b$ in $B$, has multiplicity $\min\{a,b\}$ in $C$.
To solve this problem you can preliminary sort $A$ and $B$. Then, you can keep a pointer $p_A$ to some element of $A$ and a pointer $p_B$ to some element of $B$. Initially $p_A$ (resp. $p_B$) will point to the first element of  $A$ (resp. $B$).
I will use $A[p_A]$ (resp. $B[p_B]$) to denote the element of $A$ (resp. $B$) pointed by $p_A$ (resp. $p_B$). Also, it is convenient to assume that, whenever $p_A$ (resp. $p_B$) points past the end of $A$ (resp. $B$), $A[p_A]$ (resp. $B[p_B]$) has value $+\infty$.
Proceed similarly to the merge step of Mergesort:

Initialize $C$ as an empty array.
While ($p_A$ is not past the end of $A$) or ($p_B$ is not past the end of $B$)

If $A[p_A] = B[p_B]$:

Append $A[p_A]$ to $C$.
Advance $p_A$
Advance $p_B$.


Else if $A[p_A] &gt; B[p_B]$:

Advance $p_B$


Else (in this case $A[p_A] &lt; B[p_B]$):

Advance $p_A$