\lstset{
    language=Python,
    basicstyle=\footnotesize,
    columns=flexible,
    literate={{–}{\textendash}2
              {—}{\textemdash}2}
    }

\definecolor{commentgray}{rgb}{0.3, 0.3, 0.3}
\definecolor{codegray}{rgb}{0, 0, 0}
\definecolor{stringgreen}{rgb}{0, 0.6, 0}
\definecolor{backcolour}{rgb}{0.95, 0.95, 0.95}
\definecolor{numberblue}{rgb}{0, 0.3, 1}
\definecolor{codepurple}{rgb}{0.5, 0, 0.5}

\lstdefinestyle{pystyle}{
backgroundcolor=\color{backcolour},
commentstyle=\color{commentgray},
keywords=[2]{self, __init__},
keywordstyle=\color{blue},
keywordstyle=[2]\color{codepurple},
numberstyle=\tiny\color{codegray},
stringstyle=\color{stringgreen},
basicstyle=\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2
}
%\lstset{style=mystyle}

%for inline code comments
\newcommand{\code}[1]{\colorbox{lightgray}{#1}}