% Created 2010-10-11 Mon 23:02
\documentclass[presentation]{beamer}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fixltx2e}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{soul}
\usepackage{t1enc}
\usepackage{textcomp}
\usepackage{marvosym}
\usepackage{wasysym}
\usepackage{latexsym}
\usepackage{amssymb}
\usepackage{hyperref}
\tolerance=1000
\usepackage[english]{babel} \usepackage{ae,aecompl}
\usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
\usepackage{listings}
\lstset{language=Python, basicstyle=\ttfamily\bfseries,
commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
showstringspaces=false, keywordstyle=\color{blue}\bfseries}
\providecommand{\alert}[1]{\textbf{#1}}

\title{Dictionaries}
\author{FOSSEE}
\date{}

\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
\begin{document}

\maketitle









\begin{frame}
\frametitle{Outline}
\label{sec-1}

\begin{itemize}
\item Creating dictionaries

\begin{itemize}
\item empty dictionaries
\item with data
\end{itemize}

\item Keys and values
\item Checking for elements
\item Iterating over elements
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Overview of Dictionaries}
\label{sec-2}

\begin{itemize}
\item A dictionary contains meaning of words

\begin{itemize}
\item \emph{Word} is the \emph{key} here.
\item \emph{Meaning} is the \emph{value} here.
\end{itemize}

\item A Key-Value pair data structure

\begin{itemize}
\item Provide key-value mappings
\end{itemize}

\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Creating dictionary}
\label{sec-3}

\begin{itemize}
\item Empty dictionary

\begin{itemize}
\item \texttt{mt\_dict = \{\}}

\begin{itemize}
\item \texttt{[]} - lists
\item \texttt{\{\}} - dictionaries
\end{itemize}

\end{itemize}

\item With data
\begin{verbatim}
extensions = {'jpg' : 'JPEG Image', 
              'py' : 'Python script',
              'html' : 'Html document', 
              'pdf' : 'Portable Document Format'}
\end{verbatim}

   \textbf{Note} - ordering in dictionaries cannot be relied on
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Accessing Elements}
\label{sec-4}

\begin{itemize}
\item syntax
\begin{verbatim}
     extensions[key]
\end{verbatim}

\end{itemize}

  
\begin{verbatim}
   In []: print extensions['jpg']
   Out []: JPEG Image
   In []: print extensions['zip']
\end{verbatim}
\end{frame}
\begin{frame}[fragile]
\frametitle{Adding and Deleting values}
\label{sec-5}

\begin{itemize}
\item Adding a new value
\begin{verbatim}
     In []: extension['cpp'] = 'C++ code'
\end{verbatim}

    adds a new key \emph{cpp} with \emph{C++ code} as value
\item Deleting values
\begin{verbatim}
     In []: del extensions['pdf']
\end{verbatim}

    deletes the key-value pair identified by \emph{pdf}
\item Changing value associated with a key
\begin{verbatim}
     In []: extension['cpp'] = 'C++ source code'
\end{verbatim}

    changes the value of the existing key
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Checking for container-ship of keys}
\label{sec-6}

\begin{verbatim}
   In []: 'py' in extensions
   Out []: True
\end{verbatim}

  Returns \textbf{True} if the \emph{key} is found.
\begin{verbatim}
   In []: 'odt' in extensions
   Out []: False
\end{verbatim}

  Returns \textbf{False} if the \emph{key} is not found.
\end{frame}
\begin{frame}[fragile]
\frametitle{Retrieve keys and values}
\label{sec-7}

\begin{itemize}
\item \texttt{.keys()} method
\begin{verbatim}
     In []: extensions.keys()
\end{verbatim}

    Returns a list of keys in the dictionary.
\item \texttt{.values()} method
\begin{verbatim}
     In []: extensions.values()
\end{verbatim}

    Returns the list of values in the dictionary.
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Exercise 1}
\label{sec-8}

  Print the keys and values in the dictionary one by one.
\end{frame}
\begin{frame}
\frametitle{Summary}
\label{sec-9}

\begin{itemize}
\item Creating dictionaries

\begin{itemize}
\item empty dictionaries
\item with data
\end{itemize}

\item \texttt{.keys()} method
\item \texttt{.values()} method
\item Iterating over dictionaries
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Thank you!}
\label{sec-10}

  \begin{block}{}
  \begin{center}
  This spoken tutorial has been produced by the
  \textcolor{blue}{FOSSEE} team, which is funded by the 
  \end{center}
  \begin{center}
    \textcolor{blue}{National Mission on Education through \\
      Information \& Communication Technology \\ 
      MHRD, Govt. of India}.
  \end{center}  
  \end{block}
\end{frame}

\end{document}
