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