\documentclass[twocolumn]{article}
% \documentclass{article}

\setlength{\oddsidemargin}{-0.5in}
\setlength{\evensidemargin}{-0.5in}
\setlength{\topmargin}{0.0in}
\setlength{\headheight}{0in}
\setlength{\headsep}{0in}
\setlength{\textwidth}{7.0in}
\setlength{\textheight}{9.5in}
\setlength{\parindent}{0in}
\setlength{\parskip}{0.05in}
\setlength{\columnseprule}{0.3pt} 

\setlength\columnsep{25pt}

\usepackage{fancyvrb}
\usepackage{relsize}
\usepackage{hyperref}

\usepackage{listings}
\usepackage{amsmath}

\begin{document}

\lstset{xleftmargin=5mm,framexleftmargin=10mm,basicstyle=\footnotesize}

Name: \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

Directions: MAKE SURE TO COPY YOUR ANSWERS TO A SEPARATE SHEET FOR SENDING
ME AN ELECTRONIC COPY LATER.

{\bf 1.} (15) Say I run

\begin{lstlisting}
>>> x = {'a':1,'b':5,'c':2}
\end{lstlisting}

and I would like to know what methods are available for the dictionary
class. Show the call I could use to do this.

{\bf 2.} (15) Consider the server code on p.83.  Suppose we would like to
insert code between lines 49 and 50 that prints out the number of
clients left.  Write such code.

{\bf 3.} (15) We have emphasized that with threaded code, communication
between threads is done vi global variables. Find a specific example in
our text, with page and line numbers, in which this communication is
occurring, where the change to a global by one thread will trigger an
action in another thread.  Your example must either be a line that makes
such a change or reacts to one.

{\bf 4.} (15) Threads systems typically have a {\it yield} operation,
in which is thread basically says, ``I give up my turn.'' In Python,
this can be done via the call {\bf time.sleep(0)}. Show the page and
line number where this would reduce wasted execution of a thread.

{\bf 5.} (40) The code below returns the keys of the items in dictionary
{\bf dct} that are greater than {\bf v}.  

Example:

\begin{lstlisting}
>>> x = {'a':1, 'b':3, 'c':2}
>>> highvals(x,2)
['b']
>>> highvals(x,0.5)
['a', 'c', 'b']
>>> highvals(x,1.6)
['c', 'b']
\end{lstlisting}

Fill in the blanks.

\begin{lstlisting}
def highvals(dct,v):
   return(blank (a)( \
        lambda dctitm: \
        blank (b), \
        blank (c))
\end{lstlisting}

\newpage
\onecolumn

{\bf Solutions:}

{\bf 1.} 

\begin{lstlisting}
>>> dir(x)
\end{lstlisting}

{\bf 2.}

\begin{lstlisting}
print len(cs)
\end{lstlisting}

{\bf 3.} Page 89, line 35.

{\bf 4.} Page 90, line 72.

{\bf 5.}

\begin{lstlisting}
def highvals(dct,v): \
   return(filter( \
      lambda dctitm:  \
      dct[dctitm] > v, \
      dct.keys()))
\end{lstlisting}

\end{document} 

