288 fields = record.split(';') |
288 fields = record.split(';') |
289 \end{lstlisting} |
289 \end{lstlisting} |
290 \end{frame} |
290 \end{frame} |
291 |
291 |
292 \begin{frame}[fragile] |
292 \begin{frame}[fragile] |
293 \frametitle{Dictionary} |
|
294 \begin{itemize} |
|
295 \item lists index: 0 \ldots n |
|
296 \item dictionaries index using any hashable objects |
|
297 \item d = \{ ``Hitchhiker's guide'' : 42, ``Terminator'' : ``I'll be back''\} |
|
298 \item d[``Terminator''] => ``I'll be back'' |
|
299 \item ``Terminator'' is called the key of \typ{d} |
|
300 \item ``I'll be back'' is called the value of the key ``Terminator'' |
|
301 \end{itemize} |
|
302 \end{frame} |
|
303 |
|
304 \begin{frame}[fragile] |
|
305 \frametitle{Dictionary - Building parsed data} |
293 \frametitle{Dictionary - Building parsed data} |
306 \begin{itemize} |
294 \begin{itemize} |
307 \item Let the parsed data be stored in dictionary \typ{data} |
295 \item Let the parsed data be stored in dictionary \typ{data} |
308 \item Keys of \typ{data} are strings - region codes |
296 \item \begin{lstlisting} |
309 \item Value of the key is another dictionary. |
297 data = {} # is an empty dictionary |
|
298 \end{lstlisting} |
|
299 \item Index of a dictionary is called a \emph{key} |
|
300 \item \emph{Keys} of \typ{data} are strings - region codes |
|
301 \item Value of a \emph{key} can be any Python object |
|
302 \end{itemize} |
|
303 \end{frame} |
|
304 |
|
305 \begin{frame}[fragile] |
|
306 \frametitle{Dictionary - Building parsed data...} |
|
307 \begin{itemize} |
|
308 \item In this problem let the value of a \emph{key} be another dictionary. |
310 \item This dictionary contains: |
309 \item This dictionary contains: |
311 \begin{itemize} |
310 \begin{itemize} |
312 \item 'marks': A list of NumPy arrays |
311 \item 'marks': A \emph{list} of NumPy arrays |
313 \item 'total': Total marks of each student |
312 \item 'total': Total marks of each student |
314 \item 'P': Number of passes |
313 \item 'P': Number of passes |
315 \item 'F': Number of failures |
314 \item 'F': Number of failures |
316 \item 'W': Number of withdrawls |
315 \item 'W': Number of withdrawls |
317 \end{itemize} |
316 \end{itemize} |