dictionaries/slides.tex
changeset 300 a130a1f494c3
equal deleted inserted replaced
299:8d61625510b6 300:a130a1f494c3
       
     1 % Created 2010-10-11 Mon 23:02
       
     2 \documentclass[presentation]{beamer}
       
     3 \usepackage[latin1]{inputenc}
       
     4 \usepackage[T1]{fontenc}
       
     5 \usepackage{fixltx2e}
       
     6 \usepackage{graphicx}
       
     7 \usepackage{longtable}
       
     8 \usepackage{float}
       
     9 \usepackage{wrapfig}
       
    10 \usepackage{soul}
       
    11 \usepackage{t1enc}
       
    12 \usepackage{textcomp}
       
    13 \usepackage{marvosym}
       
    14 \usepackage{wasysym}
       
    15 \usepackage{latexsym}
       
    16 \usepackage{amssymb}
       
    17 \usepackage{hyperref}
       
    18 \tolerance=1000
       
    19 \usepackage[english]{babel} \usepackage{ae,aecompl}
       
    20 \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
       
    21 \usepackage{listings}
       
    22 \lstset{language=Python, basicstyle=\ttfamily\bfseries,
       
    23 commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
       
    24 showstringspaces=false, keywordstyle=\color{blue}\bfseries}
       
    25 \providecommand{\alert}[1]{\textbf{#1}}
       
    26 
       
    27 \title{Dictionaries}
       
    28 \author{FOSSEE}
       
    29 \date{}
       
    30 
       
    31 \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
       
    32 \begin{document}
       
    33 
       
    34 \maketitle
       
    35 
       
    36 
       
    37 
       
    38 
       
    39 
       
    40 
       
    41 
       
    42 
       
    43 
       
    44 \begin{frame}
       
    45 \frametitle{Outline}
       
    46 \label{sec-1}
       
    47 
       
    48 \begin{itemize}
       
    49 \item Creating dictionaries
       
    50 
       
    51 \begin{itemize}
       
    52 \item empty dictionaries
       
    53 \item with data
       
    54 \end{itemize}
       
    55 
       
    56 \item Keys and values
       
    57 \item Checking for elements
       
    58 \item Iterating over elements
       
    59 \end{itemize}
       
    60 \end{frame}
       
    61 \begin{frame}
       
    62 \frametitle{Overview of Dictionaries}
       
    63 \label{sec-2}
       
    64 
       
    65 \begin{itemize}
       
    66 \item A dictionary contains meaning of words
       
    67 
       
    68 \begin{itemize}
       
    69 \item \emph{Word} is the \emph{key} here.
       
    70 \item \emph{Meaning} is the \emph{value} here.
       
    71 \end{itemize}
       
    72 
       
    73 \item A Key-Value pair data structure
       
    74 
       
    75 \begin{itemize}
       
    76 \item Provide key-value mappings
       
    77 \end{itemize}
       
    78 
       
    79 \end{itemize}
       
    80 \end{frame}
       
    81 \begin{frame}[fragile]
       
    82 \frametitle{Creating dictionary}
       
    83 \label{sec-3}
       
    84 
       
    85 \begin{itemize}
       
    86 \item Empty dictionary
       
    87 
       
    88 \begin{itemize}
       
    89 \item \texttt{mt\_dict = \{\}}
       
    90 
       
    91 \begin{itemize}
       
    92 \item \texttt{[]} - lists
       
    93 \item \texttt{\{\}} - dictionaries
       
    94 \end{itemize}
       
    95 
       
    96 \end{itemize}
       
    97 
       
    98 \item With data
       
    99 \begin{verbatim}
       
   100 extensions = {'jpg' : 'JPEG Image', 
       
   101               'py' : 'Python script',
       
   102               'html' : 'Html document', 
       
   103               'pdf' : 'Portable Document Format'}
       
   104 \end{verbatim}
       
   105 
       
   106    \textbf{Note} - ordering in dictionaries cannot be relied on
       
   107 \end{itemize}
       
   108 \end{frame}
       
   109 \begin{frame}[fragile]
       
   110 \frametitle{Accessing Elements}
       
   111 \label{sec-4}
       
   112 
       
   113 \begin{itemize}
       
   114 \item syntax
       
   115 \begin{verbatim}
       
   116      extensions[key]
       
   117 \end{verbatim}
       
   118 
       
   119 \end{itemize}
       
   120 
       
   121   
       
   122 \begin{verbatim}
       
   123    In []: print extensions['jpg']
       
   124    Out []: JPEG Image
       
   125    In []: print extensions['zip']
       
   126 \end{verbatim}
       
   127 \end{frame}
       
   128 \begin{frame}[fragile]
       
   129 \frametitle{Adding and Deleting values}
       
   130 \label{sec-5}
       
   131 
       
   132 \begin{itemize}
       
   133 \item Adding a new value
       
   134 \begin{verbatim}
       
   135      In []: extension['cpp'] = 'C++ code'
       
   136 \end{verbatim}
       
   137 
       
   138     adds a new key \emph{cpp} with \emph{C++ code} as value
       
   139 \item Deleting values
       
   140 \begin{verbatim}
       
   141      In []: del extensions['pdf']
       
   142 \end{verbatim}
       
   143 
       
   144     deletes the key-value pair identified by \emph{pdf}
       
   145 \item Changing value associated with a key
       
   146 \begin{verbatim}
       
   147      In []: extension['cpp'] = 'C++ source code'
       
   148 \end{verbatim}
       
   149 
       
   150     changes the value of the existing key
       
   151 \end{itemize}
       
   152 \end{frame}
       
   153 \begin{frame}[fragile]
       
   154 \frametitle{Checking for container-ship of keys}
       
   155 \label{sec-6}
       
   156 
       
   157 \begin{verbatim}
       
   158    In []: 'py' in extensions
       
   159    Out []: True
       
   160 \end{verbatim}
       
   161 
       
   162   Returns \textbf{True} if the \emph{key} is found.
       
   163 \begin{verbatim}
       
   164    In []: 'odt' in extensions
       
   165    Out []: False
       
   166 \end{verbatim}
       
   167 
       
   168   Returns \textbf{False} if the \emph{key} is not found.
       
   169 \end{frame}
       
   170 \begin{frame}[fragile]
       
   171 \frametitle{Retrieve keys and values}
       
   172 \label{sec-7}
       
   173 
       
   174 \begin{itemize}
       
   175 \item \texttt{.keys()} method
       
   176 \begin{verbatim}
       
   177      In []: extensions.keys()
       
   178 \end{verbatim}
       
   179 
       
   180     Returns a list of keys in the dictionary.
       
   181 \item \texttt{.values()} method
       
   182 \begin{verbatim}
       
   183      In []: extensions.values()
       
   184 \end{verbatim}
       
   185 
       
   186     Returns the list of values in the dictionary.
       
   187 \end{itemize}
       
   188 \end{frame}
       
   189 \begin{frame}
       
   190 \frametitle{Exercise 1}
       
   191 \label{sec-8}
       
   192 
       
   193   Print the keys and values in the dictionary one by one.
       
   194 \end{frame}
       
   195 \begin{frame}
       
   196 \frametitle{Summary}
       
   197 \label{sec-9}
       
   198 
       
   199 \begin{itemize}
       
   200 \item Creating dictionaries
       
   201 
       
   202 \begin{itemize}
       
   203 \item empty dictionaries
       
   204 \item with data
       
   205 \end{itemize}
       
   206 
       
   207 \item \texttt{.keys()} method
       
   208 \item \texttt{.values()} method
       
   209 \item Iterating over dictionaries
       
   210 \end{itemize}
       
   211 \end{frame}
       
   212 \begin{frame}
       
   213 \frametitle{Thank you!}
       
   214 \label{sec-10}
       
   215 
       
   216   \begin{block}{}
       
   217   \begin{center}
       
   218   This spoken tutorial has been produced by the
       
   219   \textcolor{blue}{FOSSEE} team, which is funded by the 
       
   220   \end{center}
       
   221   \begin{center}
       
   222     \textcolor{blue}{National Mission on Education through \\
       
   223       Information \& Communication Technology \\ 
       
   224       MHRD, Govt. of India}.
       
   225   \end{center}  
       
   226   \end{block}
       
   227 \end{frame}
       
   228 
       
   229 \end{document}