<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="https://script.spoken-tutorial.org/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=Python%2FC3%2FDictionaries%2FEnglish</id>
		<title>Python/C3/Dictionaries/English - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=Python%2FC3%2FDictionaries%2FEnglish"/>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=Python/C3/Dictionaries/English&amp;action=history"/>
		<updated>2026-04-27T03:02:33Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.23.17</generator>

	<entry>
		<id>https://script.spoken-tutorial.org/index.php?title=Python/C3/Dictionaries/English&amp;diff=1033&amp;oldid=prev</id>
		<title>Pravin1389: Created page with '{| border=1 !Visual Cue !Narration |- | Show Slide 1   Containing title, name of the production team along with the logo of MHRD  | Hello friends and Welcome to the spoken tutori…'</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=Python/C3/Dictionaries/English&amp;diff=1033&amp;oldid=prev"/>
				<updated>2012-12-02T10:16:25Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;#039;{| border=1 !Visual Cue !Narration |- | Show Slide 1   Containing title, name of the production team along with the logo of MHRD  | Hello friends and Welcome to the spoken tutori…&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{| border=1&lt;br /&gt;
!Visual Cue&lt;br /&gt;
!Narration&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 1 &lt;br /&gt;
&lt;br /&gt;
Containing title, name of the production team along with the logo of MHRD &lt;br /&gt;
| Hello friends and Welcome to the spoken tutorial on 'dictionaries'.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 2 &lt;br /&gt;
&lt;br /&gt;
Learning objectives &lt;br /&gt;
| At the end of this tutorial, you will be able to,&lt;br /&gt;
&lt;br /&gt;
# Create dictionaries.&lt;br /&gt;
# Add and delete data from dictionaries.&lt;br /&gt;
# Retrieve data from dictionaries.&lt;br /&gt;
# Check for container-ship of keys.&lt;br /&gt;
# Iterate over elements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 3 &lt;br /&gt;
&lt;br /&gt;
Pre-requisite slide &lt;br /&gt;
| Before beginning this tutorial,we would suggest you to complete the tutorial on &amp;quot;Basic datatypes and operators&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 4&lt;br /&gt;
&lt;br /&gt;
Overview of dictionaries &lt;br /&gt;
| A dictionary in general, is designed to look up for meanings of words. Similarly, Python dictionary is also designed to look up for a specific key and retrieve the corresponding value. Dictionaries are data structures that provide key-value mappings. Dictionaries are similar to lists except that instead of the values having integer indexes, dictionaries have keys or strings as indexes.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Open the terminal &lt;br /&gt;
&lt;br /&gt;
 ipython&lt;br /&gt;
| We start our ipython interpreter as,&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  mt_dict = {}&lt;br /&gt;
| Let us start by creating an empty dictionary. Type the following in your IPython interpreter.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| move the mouse over curly braces &lt;br /&gt;
| Notice that unlike lists, curly braces are used to define a &amp;lt;tt&amp;gt;dictionary&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  extensions = {'jpg' : 'JPEG Image', 'py' : 'Python script',&lt;br /&gt;
 'html' : 'Html document', 'pdf' : 'Portable Document Format'}&lt;br /&gt;
| Now let us see how to create a non-empty dictionary,&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Move the mouse over the commas &lt;br /&gt;
| Notice that each key-value pair is separated by a comma.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Move the mouse over the colon one by one &lt;br /&gt;
| and each key and value are separated using a colon.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  extensions&lt;br /&gt;
| Here, we have defined four entries in the dictionary extensions. The keys are&lt;br /&gt;
&lt;br /&gt;
jpg, py, html, and pdf.&lt;br /&gt;
&lt;br /&gt;
Simply type,extensions in the interpreter to see the content of the dictionary.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 5 &lt;br /&gt;
&lt;br /&gt;
Accessing elements &lt;br /&gt;
| Notice that, in dictionaries, the order cannot be predicted and you can see that the values are not in the order that we entered in.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Switch to terminal &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;print extensions['jpg']&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| Like in lists, the elements in a dictionary can be accessed using the index, here the index is the key. We type,&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;nowiki&amp;gt;print extensions['zip']&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| It printed JPEG Image. And now try,&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;nowiki&amp;gt;extensions['cpp'] = 'C++ code'&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| Well it gave us an error, saying that the key 'zip' is not in the dictionary.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;nowiki&amp;gt;Pause here for some time and try few more keys. Also try jpg in capital letters. &amp;lt;continue from paused state&amp;gt; Well that was about creating dictionaries, now how do we add or delete items. We can add new items into dictionaries as,&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;nowiki&amp;gt;del extensions['pdf']&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| and delete items using the &amp;lt;tt&amp;gt;del&amp;lt;/tt&amp;gt; keyword as,&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  extensions&lt;br /&gt;
| Let us check the content of the dictionary now,&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;nowiki&amp;gt;extensions['cpp'] = 'C++ source code'&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 extensions&lt;br /&gt;
| So the changes have been made. Now let us try one more thing,&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  'py' in extensions&lt;br /&gt;
 'odt' in extensions&lt;br /&gt;
| As you can see, it neither added a new thing nor gave an error, but it simply replaced the existing value with the new one.&lt;br /&gt;
&lt;br /&gt;
Now let us learn how to check if a particular key is present in the dictionary. For that we can use the method &amp;lt;tt&amp;gt;in&amp;lt;/tt&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 6 &lt;br /&gt;
&lt;br /&gt;
Retrieve keys and values &lt;br /&gt;
| It will return &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt; if the key is found in the dictionary, and will return &amp;lt;tt&amp;gt;False&amp;lt;/tt&amp;gt; if key is not present. Note that we can check only for container-ship of keys in dictionaries and not values.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
| Now let us see how to retrieve the keys and values. We can use the method &amp;lt;tt&amp;gt;keys()&amp;lt;/tt&amp;gt; for getting a list of the keys in a particular dictionary and the method &amp;lt;tt&amp;gt;values()&amp;lt;/tt&amp;gt; for getting a list of values.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Switch to terminal &lt;br /&gt;
&lt;br /&gt;
 extensions.keys()&lt;br /&gt;
| Let us try them,&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  extensions.values()&lt;br /&gt;
| It returned the &amp;lt;tt&amp;gt;list&amp;lt;/tt&amp;gt; of keys in the dictionary extensions. And now the other one,&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
| It returned the &amp;lt;tt&amp;gt;list&amp;lt;/tt&amp;gt; of values in the dictionary.&lt;br /&gt;
&lt;br /&gt;
Pause the video here, try out the following exercise and resume the video.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 7 &lt;br /&gt;
&lt;br /&gt;
Assignment 1 &lt;br /&gt;
| Print the keys and values in the dictionary one by one.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Continue from paused state Switch to the terminal &lt;br /&gt;
&lt;br /&gt;
 for each in extensions.keys():&lt;br /&gt;
     &amp;lt;nowiki&amp;gt;print each, &amp;quot;--&amp;gt;&amp;quot;, extensions[each]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| Switch to terminal for solution.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 8 &lt;br /&gt;
&lt;br /&gt;
Summary slide &lt;br /&gt;
| This brings us to the end of this tutorial. In this tutorial, we have learnt to,&lt;br /&gt;
&lt;br /&gt;
# Create dictionaries namely -- - empty dictionaries - dictionaries with data.&lt;br /&gt;
# Access elements in the dictionaries using the keys.&lt;br /&gt;
# Add elements to a dictionary by assigning a value to a key.&lt;br /&gt;
# Delete elements from a dictionary by using the function &amp;lt;tt&amp;gt;del&amp;lt;/tt&amp;gt;.&lt;br /&gt;
# Retrieve the keys and values by using the methods &amp;lt;tt&amp;gt;.keys()&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;.values()&amp;lt;/tt&amp;gt; respectively.&lt;br /&gt;
# Iterate over elements of a dictionary using a &amp;lt;tt&amp;gt;for&amp;lt;/tt&amp;gt; loop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 9 &lt;br /&gt;
&lt;br /&gt;
Self assessment questions slide &lt;br /&gt;
| Here are some self assessment questions for you to solve&lt;br /&gt;
&lt;br /&gt;
# Container-ship of values can be checked in a python dictionary&lt;br /&gt;
** True&lt;br /&gt;
** False&lt;br /&gt;
# Consider the python dictionary &amp;lt;tt&amp;gt;x = {'a' : &amp;lt;nowiki&amp;gt;['a','b','c'], 'b' : (1, 2, 3), 1 : {1 : 'one', 2 : 'two'}, 10 : {10 : 'ten', 11 : &amp;lt;/nowiki&amp;gt;'eleven'}}&amp;lt;/tt&amp;gt;. What will the following code return?&amp;lt;br/&amp;gt; Unexpected indentation.&amp;lt;br/&amp;gt; &amp;lt;tt&amp;gt;(1, 2, 3) in x.values()&amp;lt;/tt&amp;gt;.&lt;br /&gt;
** True&lt;br /&gt;
** False&lt;br /&gt;
** Container-ship of values cannot be checked in dictionaries&lt;br /&gt;
** The dictionary is invalid&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 10&lt;br /&gt;
&lt;br /&gt;
Solution of self assessment questions on slide &lt;br /&gt;
| And the answers,&lt;br /&gt;
&lt;br /&gt;
# False. Container-ship of only keys can be checked in a python dictionary.&lt;br /&gt;
# True&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 11 &lt;br /&gt;
&lt;br /&gt;
Acknowledgment slide &lt;br /&gt;
| Hope you have enjoyed this tutorial and found it useful. Thank you!&lt;br /&gt;
&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Pravin1389</name></author>	</entry>

	</feed>