If we decide to write multiple versions of a book using different programming languages to solve the same problem and target slightly different audiences, then it would be a giant waste of time to write books in a traditional way. Obviously, LaTeX is the best way to do so.

We can split all chapters into different files. Assuming that the text description does not change because we simply describe the same thing but using a different programming language only (e.g. Python and Julia), then it is simple to change the listings. The probably simplest way to include listings into a LaTeX document is using minted.

[...]

\usepackage{minted}

[...]

\begin{minted}[<options>]{language}

<insert code listing>

\end{minted}

If we have files containing our source code, then we can include them by using:

% if we want captions and label, then we have to use the listing environment
% \begin{listing}[!ht]

\inputminted[<options: firstline=x, lastline=y>]{<language>}{file}

% add caption and label:
% \caption{<caption>}
% \label{listing:foo}
% \end{listing}

If we want to generate the books/papers completely automatically, then we should write a macro that switches the filename extension according to our chosen programming language. This is also a nice way to keep certain documents updated if the source code changes (e.g. from Python 2.x to 3.x, or Julia 0.4.x to 1.0).