author | Puneeth Chaganti <punchagan@fossee.in> |
Thu, 07 Oct 2010 12:28:12 +0530 | |
changeset 242 | a33e942379d7 |
parent 160 | f394adb5b00e |
permissions | -rw-r--r-- |
160
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
1 |
.. 8.4 LO: dictionaries (2) |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
2 |
.. ------------------------ |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
3 |
.. * empty |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
4 |
.. * filled |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
5 |
.. * accessing via keys |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
6 |
.. * .values(), .keys() |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
7 |
.. * in |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
8 |
.. * iteration |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
9 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
10 |
============ |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
11 |
Dictionaries |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
12 |
============ |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
13 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
14 |
{{{ show the welcome slide }}} |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
15 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
16 |
Welcome to the spoken tutorial on dictionaries. |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
17 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
18 |
{{{ switch to next slide, outline slide }}} |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
19 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
20 |
In this tutorial, we will see how to create empty dictionaries, learn |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
21 |
about keys and values of dictionaries. Checking for elements and |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
22 |
iterating over elements. |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
23 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
24 |
{{{ switch to next slide on overview of dictionaries }}} |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
25 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
26 |
A dictionary in general, is designed to look up meanings of |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
27 |
words. Similarly, Python dictionary is also designed to look up for a |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
28 |
specific key and retrieve the corresponding value. Dictionaries are |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
29 |
data structures that provide key-value mappings. Dictionaries are |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
30 |
similar to lists except that instead of the values having integer |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
31 |
indexes, dictionaries have keys or strings as indexes. |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
32 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
33 |
Before we can proceed, start your IPython interpreter with the |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
34 |
``-pylab`` option. |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
35 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
36 |
{{{ start ipython interpreter by issuing command ipython -pylab }}} |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
37 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
38 |
Let us start by creating an empty dictionary, type the following in |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
39 |
your IPython interpreter. |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
40 |
:: |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
41 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
42 |
mt_dict = {} |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
43 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
44 |
Notice that unlike lists curly braces are used define ``dictionary``, |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
45 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
46 |
{{{ move the mouse over curly braces to grab attention }}} |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
47 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
48 |
Now let us see how to create a filled dictionary, |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
49 |
:: |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
50 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
51 |
extensions = {'jpg' : 'JPEG Image', 'py' : 'Python script', 'html' : 'Html document', 'pdf' : 'Portable Document Format'} |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
52 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
53 |
Notice that each key-value pair is separated by a comma |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
54 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
55 |
{{{ move the mouse over the commas to grab attention }}} |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
56 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
57 |
and each key and value are separated using a colon. |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
58 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
59 |
{{{ move the mouse over the colon one by one to grab attention }}} |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
60 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
61 |
Here, we defined four entries in the dictionary extensions. The keys |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
62 |
are |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
63 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
64 |
{{{ spell the keys letter by letter }}} |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
65 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
66 |
jpg, py, html, and pdf. |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
67 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
68 |
Simply type, |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
69 |
:: |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
70 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
71 |
extensions |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
72 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
73 |
in the interpreter to see the content of the dictionary. Notice that |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
74 |
in dictionaries the order cannot be predicted and you can see that the |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
75 |
values are not in the order that we entered in. |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
76 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
77 |
Like in lists, the elements in a dictionary can be accessed using the |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
78 |
index, here the index is the key. Try, |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
79 |
:: |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
80 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
81 |
print extensions['jpg'] |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
82 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
83 |
It printed JPEG Image. And now try, |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
84 |
:: |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
85 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
86 |
print extensions['zip'] |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
87 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
88 |
Well it gave us an error, saying that the key 'zip' is not in the |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
89 |
dictionary. |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
90 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
91 |
Pause here for some time and try few more keys. Also try jpg in |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
92 |
capital letters. |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
93 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
94 |
{{{ switch to next slide, adding and deleting keys and values in |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
95 |
dictionaries }}} |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
96 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
97 |
Well that was about creating dictionaries, now how do we add or delete |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
98 |
items. We can add new items into dictionaries as, |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
99 |
:: |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
100 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
101 |
extensions['cpp'] = 'C++ code' |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
102 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
103 |
and delete items using the ``del`` keyword as, |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
104 |
:: |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
105 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
106 |
del extension['pdf'] |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
107 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
108 |
Let us check the content of the dictionary now, |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
109 |
:: |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
110 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
111 |
extensions |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
112 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
113 |
So the changes have been made. Now let us try one more thing, |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
114 |
:: |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
115 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
116 |
extensions['cpp'] = 'C++ source code' |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
117 |
extensions |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
118 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
119 |
As you can see, it did not add a new thing nor gave an error, but it |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
120 |
simply replaces the existing value with the new one. |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
121 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
122 |
Now let us learn how to check if a particular key is present in the |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
123 |
dictionary. For that we can use ``in``, |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
124 |
:: |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
125 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
126 |
'py' in extensions |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
127 |
'odt' in extensions |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
128 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
129 |
So in short it will return ``True`` if the key is found in the |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
130 |
dictionary, and will return ``False`` if key is not present. Note that |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
131 |
we can check only for container-ship of keys in dictionaries and not |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
132 |
values. |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
133 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
134 |
{{{ switch to next slide, Retrieve keys and values }}} |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
135 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
136 |
Now let us see how to retrieve the keys and values. We can use the |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
137 |
method ``keys()`` for getting a list of the keys in a particular |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
138 |
dictionary and the method ``values()`` for getting a list of |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
139 |
values. Let us try them, |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
140 |
:: |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
141 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
142 |
extensions.keys() |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
143 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
144 |
It returned the ``list`` of keys in the dictionary extensions. And now |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
145 |
the other one, |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
146 |
:: |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
147 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
148 |
extensions.values() |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
149 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
150 |
It returned the ``list`` of values in the dictionary. |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
151 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
152 |
{{{ switch to next slide, problem statement for the next solved |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
153 |
exercise }}} |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
154 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
155 |
Now let us try to print the data in the dictionary. We can use ``for`` |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
156 |
loop to iterate. |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
157 |
:: |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
158 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
159 |
for each in extensions.keys(): |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
160 |
print each, "-->", extensions[each] |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
161 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
162 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
163 |
{{{ switch to next slide, recap }}} |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
164 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
165 |
This brings us to the end of this tutorial, we learned dictionaries |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
166 |
and saw how to create an empty dictionary, build a dictionary with |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
167 |
some data in it, adding data, ``keys()`` and ``values()`` methods, and |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
168 |
iterating over the dictionaries. |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
169 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
170 |
{{{ switch to next slide, thank you slide }}} |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
171 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
172 |
Thank you! |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
173 |
|
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
174 |
.. Author: Anoop Jacob Thomas <anoop@fossee.in> |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
175 |
Reviewer 1: |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
176 |
Reviewer 2: |
f394adb5b00e
added savefig, dictionaries, getting_started_with_for and other_type_of_plots.
anoop
parents:
diff
changeset
|
177 |
External reviewer: |