Just for the fun of it, and in case somebody else stumbles on this: This idea can be combined with the standalone package as well, with a bit of tweaking:
\documentclass[multi=apage,varwidth=8cm]{standalone}
\usepackage{minted}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\newenvironment{apage}[0]{}{}
\begin{document}
\begin{apage}
\begin{tabular}{p{0.3\textwidth}p{0.3\textwidth}}
\begin{minted}[escapeinside=??]{py}
def f(x):
y = x?\tikzmark{here1}?2
return y
\end{minted}
&
\begin{minted}[escapeinside=??]{py}
def f(x):
y = x?\tikzmark{here2}?2
return y
\end{minted}
\end{tabular}
\begin{tikzpicture}[remember picture]
\draw[overlay, ->, line width=5pt, red]
(pic cs:here1) -- (pic cs:here2);
\end{tikzpicture}
\end{apage}
\end{document}