\documentclass{foils}

\MyLogo{}
\usepackage{color}
\usepackage[landscape,a4paper,hscale=0.9,vscale=0.9]{geometry}
\usepackage{graphicx}
\usepackage{listings}

\newcommand{\Red}[1]{\textcolor{red}{#1}}
\newcommand{\Green}[1]{\textcolor{green}{#1}}
\newcommand{\Blue}[1]{\textcolor{blue}{#1}}

\renewcommand\normalcolor{\color{blue}}

\definecolor{mauve}{rgb}{0.58,0,0.82}


\color{black}
\pagecolor{white}



\usepackage{url}

\begin{document} 
\lstset{language=Python,
        basicstyle=\small\ttfamily,
        keywordstyle=\bfseries\color{green},
        identifierstyle=\color{blue},
        stringstyle=\color{mauve},
        frame=single,
        showspaces=false,
        showstringspaces=false,
}

\author{Gertjan van Noord}
\title{\Blue{Coding for Humanities -- Python}}

\maketitle

\foilhead{Last words}

\begin{lstlisting}
words = []
for line in sys.stdin:
    line = line.rstrip()
    ws = line.split()
    if ws:
        words=words+[ws[-1]]
for w in words:
    print(w,end=" ")
print()
\end{lstlisting}

\foilhead{CVC}

\begin{lstlisting}
for line in sys.stdin:
    line = line.rstrip()
    words = line.split()
    for word in words:
        if ( len(word) == 3 and 
             word[0].lower() in "bcdfghjklmnpqrstvwxz" and
             word[1].lower() in "aeiou" and
             word[2].lower() in "bcdfghjklmnpqrstvwxz" ):
            print(word)
\end{lstlisting}

\foilhead{Sum of 5 columns}

\begin{lstlisting}
sums=[0,0,0,0,0]
for line in sys.stdin:
    line = line.rstrip()
    strs = line.split()
    for i in range(5):
        sums[i] = sums[i] + int(strs[i])

for sum in sums:
    print(sum,end=" ")
print()
\end{lstlisting}

\foilhead{Preceded by determiner}
\begin{lstlisting}
for line in sys.stdin:
    prevw=""
    line = line.rstrip()
    words = line.split()
    for word in words:
        if prevw in ["the","a","an"]:
            print(word)
        prevw=word
\end{lstlisting}

\foilhead{Maximal sequences of capitalized words}

\begin{lstlisting}
for line in sys.stdin:
    needs_nl=False
    line = line.rstrip()
    words = line.split()
    for word in words:
        if word[0].isupper():
            print(word,end=" ")
            needs_nl=True
        else:
            if needs_nl:
                print()
                needs_nl=False
    if needs_nl:
        print()
\end{lstlisting}

\end{document}
