dictionaries/slides.org
changeset 300 a130a1f494c3
equal deleted inserted replaced
299:8d61625510b6 300:a130a1f494c3
       
     1 #+LaTeX_CLASS: beamer
       
     2 #+LaTeX_CLASS_OPTIONS: [presentation]
       
     3 #+BEAMER_FRAME_LEVEL: 1
       
     4 
       
     5 #+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
       
     6 #+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra)
       
     7 #+PROPERTY: BEAMER_col_ALL 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 :ETC
       
     8 
       
     9 #+LaTeX_CLASS: beamer
       
    10 #+LaTeX_CLASS_OPTIONS: [presentation]
       
    11 
       
    12 #+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl}
       
    13 #+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
       
    14 
       
    15 #+LaTeX_HEADER: \usepackage{listings}
       
    16 
       
    17 #+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries,
       
    18 #+LaTeX_HEADER:  commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
       
    19 #+LaTeX_HEADER:  showstringspaces=false, keywordstyle=\color{blue}\bfseries}
       
    20 
       
    21 #+TITLE: Dictionaries
       
    22 #+AUTHOR: FOSSEE
       
    23 #+EMAIL: info@fossee.in   
       
    24 #+DATE:    
       
    25 
       
    26 #+DESCRIPTION: 
       
    27 #+KEYWORDS: 
       
    28 #+LANGUAGE:  en
       
    29 #+OPTIONS:   H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
       
    30 #+OPTIONS:   TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc
       
    31 
       
    32 * Outline
       
    33   - Creating dictionaries
       
    34     - empty dictionaries
       
    35     - with data
       
    36   - Keys and values
       
    37   - Checking for elements
       
    38   - Iterating over elements
       
    39 
       
    40 * Overview of Dictionaries
       
    41   - A dictionary contains meaning of words
       
    42     - /Word/ is the /key/ here.
       
    43     - /Meaning/ is the /value/ here.
       
    44   - A Key-Value pair data structure
       
    45     - Provide key-value mappings
       
    46 
       
    47 * Creating dictionary
       
    48   - Empty dictionary
       
    49     - ~mt_dict = {}~
       
    50       - ~[]~ - lists
       
    51       - ~{}~ - dictionaries
       
    52   - With data
       
    53     #+begin_src python
       
    54         extensions = {'jpg' : 'JPEG Image', 
       
    55 	              'py' : 'Python script',
       
    56                       'html' : 'Html document', 
       
    57                       'pdf' : 'Portable Document Format'}
       
    58     #+end_src
       
    59 
       
    60    *Note* - ordering in dictionaries cannot be relied on
       
    61 * Accessing Elements
       
    62   - syntax
       
    63     : extensions[key]
       
    64   
       
    65   : In []: print extensions['jpg']
       
    66   : Out []: JPEG Image
       
    67   : In []: print extensions['zip']
       
    68 * Adding and Deleting values
       
    69   - Adding a new value
       
    70     : In []: extension['cpp'] = 'C++ code'
       
    71     adds a new key /cpp/ with /C++ code/ as value
       
    72   - Deleting values
       
    73     : In []: del extensions['pdf']
       
    74     deletes the key-value pair identified by /pdf/
       
    75   - Changing value associated with a key
       
    76     : In []: extension['cpp'] = 'C++ source code'
       
    77     changes the value of the existing key
       
    78 * Checking for container-ship of keys
       
    79   : In []: 'py' in extensions
       
    80   : Out []: True
       
    81   Returns *True* if the /key/ is found.
       
    82   : In []: 'odt' in extensions
       
    83   : Out []: False
       
    84   Returns *False* if the /key/ is not found.
       
    85 
       
    86 * Retrieve keys and values
       
    87   - ~.keys()~ method
       
    88     : In []: extensions.keys()
       
    89     Returns a list of keys in the dictionary.
       
    90   - ~.values()~ method
       
    91     : In []: extensions.values()
       
    92     Returns the list of values in the dictionary.
       
    93 * Exercise 1
       
    94   Print the keys and values in the dictionary one by one.
       
    95 * Summary
       
    96   - Creating dictionaries
       
    97     - empty dictionaries
       
    98     - with data
       
    99   - ~.keys()~ method
       
   100   - ~.values()~ method
       
   101   - Iterating over dictionaries
       
   102 * Thank you!
       
   103 #+begin_latex
       
   104   \begin{block}{}
       
   105   \begin{center}
       
   106   This spoken tutorial has been produced by the
       
   107   \textcolor{blue}{FOSSEE} team, which is funded by the 
       
   108   \end{center}
       
   109   \begin{center}
       
   110     \textcolor{blue}{National Mission on Education through \\
       
   111       Information \& Communication Technology \\ 
       
   112       MHRD, Govt. of India}.
       
   113   \end{center}  
       
   114   \end{block}
       
   115 #+end_latex
       
   116 
       
   117