Difference between revisions of "Python/C3/Dictionaries/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
{| border=1
 
{| border=1
!Timing
+
|'''Time'''
!Narration
+
|'''Narration'''
 +
 
 
|-
 
|-
| 0:01
+
| 00:01
 
| Hello friends and Welcome to the spoken tutorial on 'dictionaries'.
 
| Hello friends and Welcome to the spoken tutorial on 'dictionaries'.
  
 
|-
 
|-
| 0:05  
+
| 00:05  
 
| At the end of this tutorial, you will be able to,
 
| At the end of this tutorial, you will be able to,
 
+
Create dictionaries.
# Create dictionaries.
+
Add and delete data from dictionaries.
# Add and delete data from dictionaries.
+
Retrieve data from dictionaries.
# Retrieve data from dictionaries.
+
Check for container-ship of keys.
# Check for container-ship of keys.
+
Iterating  over elements.
# Iterating  over elements.
+
  
 
|-
 
|-
0:20
+
00:20
 
| Before beginning this tutorial,we would suggest you to complete the tutorial on "Basic datatypes and operators".
 
| Before beginning this tutorial,we would suggest you to complete the tutorial on "Basic datatypes and operators".
  
 
|-
 
|-
| 0:27  
+
| 00:27  
 
| A dictionary in general, is designed to look up for meanings of words.
 
| A dictionary in general, is designed to look up for meanings of words.
  
 
|-
 
|-
|0:35
+
|00:35
 
| Similarly, Python dictionary is also designed to look up for a specific key and retrieve the corresponding value.  
 
| Similarly, Python dictionary is also designed to look up for a specific key and retrieve the corresponding value.  
  
 
|-
 
|-
|0:43
+
|00:43
 
|Dictionaries are data structures that provide key-value mappings.  
 
|Dictionaries are data structures that provide key-value mappings.  
  
 
|-
 
|-
|0:47
+
|00:47
 
|Dictionaries are similar to lists except that instead of the values having integer indexes, dictionaries have keys or strings as indexes.
 
|Dictionaries are similar to lists except that instead of the values having integer indexes, dictionaries have keys or strings as indexes.
  
 
|-
 
|-
| 0:58
+
| 00:58
 
| We start our ipython interpreter as, ipython
 
| We start our ipython interpreter as, ipython
  
 
|-
 
|-
1:07
+
01:07
 
| Let us start by creating an empty dictionary.
 
| Let us start by creating an empty dictionary.
  
 
|-
 
|-
|1:12
+
|01:12
 
| Type the following in your IPython interpreter,mt underscore dict = closing curly brackets
 
| Type the following in your IPython interpreter,mt underscore dict = closing curly brackets
  
 
|-
 
|-
| 1:25
+
| 01:25
 
| Notice that unlike lists, curly braces are used to define a dictionary
 
| Notice that unlike lists, curly braces are used to define a dictionary
  
 
|-
 
|-
|1:33
+
|01:33
 
| Now let us see how to create a non-empty dictionary,
 
| Now let us see how to create a non-empty dictionary,
  
 
|-
 
|-
|1:37
+
|01:37
 
|so type extensions = open curly brackets  in single quotes jpg colon  'JPEG Image' comma  'py'  colon  'Python script' comma  
 
|so type extensions = open curly brackets  in single quotes jpg colon  'JPEG Image' comma  'py'  colon  'Python script' comma  
  
 
'html'  colon  'Html document' comma pdf  colon  Portable Document Format close curly brackets
 
'html'  colon  'Html document' comma pdf  colon  Portable Document Format close curly brackets
 
   
 
   
 
 
|-
 
|-
| 2:08
+
| 02:08
 
| Notice that each key-value pair is separated by a comma.
 
| Notice that each key-value pair is separated by a comma.
  
 
|-
 
|-
2:17
+
02:17
| and each key and value are separated using a colon.
+
| and each key value are separated using a colon.
  
 
|-
 
|-
2:23
+
02:23
 
| Here, we have defined four entries in the dictionary extensions.  
 
| Here, we have defined four entries in the dictionary extensions.  
  
 
|-
 
|-
|2:29
+
|02:29
 
|The keys are jpg comma  py comma  html comma  and pdf.
 
|The keys are jpg comma  py comma  html comma  and pdf.
  
 
|-
 
|-
|2:36
+
|02:36
 
|Simply type,extensions in the interpreter to see the content of the dictionary.
 
|Simply type,extensions in the interpreter to see the content of the dictionary.
  
 
|-
 
|-
|2:40
+
|02:40
 
|So type extensions.
 
|So type extensions.
  
 
|-
 
|-
| 2:45  
+
| 02:45  
 
| 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.
 
| 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.
  
 
|-
 
|-
| 2:53
+
| 02:53
 
| Like lists, the elements in a dictionary can be accessed using the index, here the index is the key.
 
| Like lists, the elements in a dictionary can be accessed using the index, here the index is the key.
  
 
|-
 
|-
|3:06
+
|03:06
| We type, print extensions within closing brackets and single quotes jpg.
+
| We type, print extensions in closing brackets in single quotes jpg.
  
 
|-
 
|-
| 3:25
+
| 03:25
| It printed JPEG Image. And now type print extensions within square brackets zip.
+
|NOW It printed JPEG Image. And now type print extensions within square brackets zip.
  
 
|-
 
|-
3:42
+
03:42
 
| Well it gave us an error, saying that the key 'zip' is not in the dictionary.
 
| Well it gave us an error, saying that the key 'zip' is not in the dictionary.
  
 
|-
 
|-
|3:48
+
|03:48
 
|So Pause here for some time and try few more keys.
 
|So Pause here for some time and try few more keys.
  
 
|-
 
|-
|3:52
+
|03:52
 
| Also try jpg in capital letters.  
 
| Also try jpg in capital letters.  
  
 
|-
 
|-
|3:58
+
|03:58
|<continue from paused state> Well that was about creating dictionaries, now how do we add or delete items.
+
|<continue from paused state Well that was about creating dictionaries, now how do we add or delete items?
  
 
|-
 
|-
|4:09
+
|04:09
 
| We can add new items into dictionaries as,
 
| We can add new items into dictionaries as,
  
 
|-
 
|-
|4:13
+
|04:13
|Type extensions within square brackets and single quotes cpp is equal to in single quotes C++ then code.
+
|Type extensions within square brackets in single quotes cpp is equal to in single quotes C++ then code.
  
 
|-
 
|-
4:36
+
04:36
| and delete items using the  del  keyword as, type del space extensions within square brackets and single quotes pdf.
+
| and delete items using the  del  keyword as, type del space extensions and in square brackets and single quotes pdf.
  
 
|-
 
|-
4:51
+
04:51
 
| Let us check the content of the dictionary now,
 
| Let us check the content of the dictionary now,
  
 
|-
 
|-
|4:54
+
|04:54
 
|So type extensions.
 
|So type extensions.
  
 
|-
 
|-
| 4:57
+
| 04:57
 
| So the changes have been made.
 
| So the changes have been made.
  
 
|-
 
|-
|4:59
+
|04:59
| Now let us try one more thing, type extensions within square brackets and in single quotes cpp is equal to in single quote C++ and source code. then type again extensions.
+
|let us try one more thing, type extensions within square brackets and in single quotes cpp is equal to in single quote C++ and source code. then type again extensions.
  
 
|-
 
|-
5:21
+
05:21
 
| 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.
 
| 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.
  
 
|-
 
|-
|5:29
+
|05:29
 
|Now let us learn how to check if a particular key is present in the dictionary.
 
|Now let us learn how to check if a particular key is present in the dictionary.
  
 
|-
 
|-
|5:33
+
|05:33
 
| For that we can use the method in,
 
| For that we can use the method in,
  
 
|-
 
|-
|5:37
+
|05:37
 
|So type within single quotes py in extensions.
 
|So type within single quotes py in extensions.
  
 
|-
 
|-
|5:45
+
|05:45
|Then type within single quotes odt in extensions.  
+
|Then type odt in extensions.  
  
 
|-
 
|-
| 5:53
+
| 05:53
 
| It will return True  if the key is found in the dictionary, and will return False if key is not present.
 
| It will return True  if the key is found in the dictionary, and will return False if key is not present.
  
 
|-
 
|-
|6:00
+
|06:00
 
| Note that we can check only for container-ship of keys in dictionaries and not values.
 
| Note that we can check only for container-ship of keys in dictionaries and not values.
  
 
|-
 
|-
| 6:07
+
| 06:07
 
| Now let us see how to retrieve the keys and values.
 
| Now let us see how to retrieve the keys and values.
  
 
|-
 
|-
|6:10
+
|06:10
 
| We can use the method keys() for getting a list of the keys in a particular dictionary and the method values() for getting a list of values.
 
| We can use the method keys() for getting a list of the keys in a particular dictionary and the method values() for getting a list of values.
  
 
|-
 
|-
| 6:20
+
| 06:20
| Let us try them, type extensions dot keys closing brackets.
+
| Let us try them, type extensions dot key closing brackets.
  
 
|-
 
|-
6:31
+
06:31
 
| It returned the list of keys in the dictionary extensions.
 
| It returned the list of keys in the dictionary extensions.
  
 
|-
 
|-
|6:35
+
|06:35
 
| And now the other one is extensions dot values and closing brackets.
 
| And now the other one is extensions dot values and closing brackets.
  
 
|-
 
|-
| 6:42
+
| 06:42
 
| It returned the list of values in the dictionary.
 
| It returned the list of values in the dictionary.
  
 
|-
 
|-
|6:45
+
|06:45
 
|Pause the video here, try out the following exercise and resume the video.
 
|Pause the video here, try out the following exercise and resume the video.
  
 
|-
 
|-
6:49
+
06:49
 
| Print the keys and values in the dictionary one by one.
 
| Print the keys and values in the dictionary one by one.
  
 
|-
 
|-
|6:54
+
|06:54
| Switch to terminal for solution.
+
|Now Switch to terminal for solution.
  
 
|-
 
|-
|6:58
+
|06:58
|Type for each in extensions dot keys closing brackets colon then,
+
|Type for each in extensions dot keys closing brackets colon then, print each comma within double quotes hyphen hyphen greater symbol, extensions and in square  brackets each.
    print each comma within double quotes hyphen hyphen greater symbol, extensions and within closing brackets each.
+
  
 
|-
 
|-
| 7:35
+
| 07:35
 
| This brings us to the end of this tutorial.  
 
| This brings us to the end of this tutorial.  
  
 
|-
 
|-
|7:39
+
|07:39
 
|In this tutorial, we have learn't to,
 
|In this tutorial, we have learn't to,
  
 
|-
 
|-
|7:41
+
|07:41
|1. Create dictionaries namely -- - empty dictionaries - dictionaries with data.
+
|Create dictionaries namely -- - empty dictionaries - dictionaries with data.
  
 
|-
 
|-
|7:45
+
|07:45
|2. Access elements in the dictionaries using the keys.
+
|Access elements in the dictionaries using the keys.
  
 
|-
 
|-
|7:49
+
|07:49
|3. Add elements to a dictionary by assigning a key value.
+
|Add elements to a dictionary by assigning a key value.
 +
 
 
|-
 
|-
|7:55
+
|07:55
|4. Delete elements from a dictionary by using the function del
+
|Delete elements from a dictionary by using the function del
  
 
|-
 
|-
|8:00
+
|08:00
|5. Retrieve the keys and values by using the methods .keys() and.values() respectively.
+
|Retrieve the keys and values by using the methods .keys() and.values() respectively.
  
 
|-
 
|-
|8:06
+
|08:06
|6. Iterate over elements of a dictionary using a for loop.
+
|Iterate over elements of a dictionary using a for loop.
  
 
|-
 
|-
| 8:11
+
| 08:11
 
| Here are some self assessment questions for you to solve
 
| Here are some self assessment questions for you to solve
  
 
|-
 
|-
|8:15
+
|08:15
|1. First one, Container-ship of values can be checked in a python dictionary - true or false.
+
|First one, Container-ship of values can be checked in a python dictionary - true or false.
  
 
|-
 
|-
|8:22
+
|08:22
|2. Second one is, Consider the python dictionary x is equal to within curly brackets 'a' colon ['a','b','c'], 'b' colon (1, 2, 3), 1 colon then again another curly braces 1 colon 'one' comma 2 colon 'two' comma 10 colon within curly brackets 10 colon 'ten', 11 colon 'eleven' and close the curly brackets.
+
|Second one is, Consider the python dictionary x is equal to within curly brackets 'a' colon ['a','b','c'], 'b' colon (1, 2, 3), 1 colon then again another curly braces 1 colon 'one' comma 2 colon 'two' comma 10 colon within curly brackets 10 colon 'ten', 11 colon 'eleven' and close the curly brackets.
  
 
|-
 
|-
|8:52
+
|08:52
 
| What will the following code return?
 
| What will the following code return?
  
 
|-
 
|-
|8:57
+
|08:57
 
|(1, 2, 3) in x.values(). True. False
 
|(1, 2, 3) in x.values(). True. False
  
 
|-
 
|-
|9:05
+
|09:05
 
|Then container-ship of values cannot be checked in dictionaries
 
|Then container-ship of values cannot be checked in dictionaries
  
 
|-
 
|-
|9:10
+
|09:10
 
| The dictionary is invalid
 
| The dictionary is invalid
  
 
|-
 
|-
| 9:13
+
| 09:13
 
| So Lets look at the answers,
 
| So Lets look at the answers,
  
 
|-
 
|-
|9:16
+
|09:16
|1.The answer of first one, False.  
+
|The answer of first one, False.  
  
 
|-
 
|-
|9:19
+
|09:19
 
| Container-ship of only keys can be checked in a python dictionary.
 
| Container-ship of only keys can be checked in a python dictionary.
  
 
|-
 
|-
|9:27
+
|09:27
|2. Second one is, True
+
|Second one is, True
  
 
|-
 
|-
| 9:31
+
| 09:31
 
| Hope you have enjoyed this tutorial and found it useful.  
 
| Hope you have enjoyed this tutorial and found it useful.  
  
 
|-
 
|-
|9:35
+
|09:35
 
|Thank you!
 
|Thank you!
  
 
|}
 
|}

Latest revision as of 16:38, 20 February 2017

Time Narration
00:01 Hello friends and Welcome to the spoken tutorial on 'dictionaries'.
00:05 At the end of this tutorial, you will be able to,

Create dictionaries. Add and delete data from dictionaries. Retrieve data from dictionaries. Check for container-ship of keys. Iterating over elements.

00:20 Before beginning this tutorial,we would suggest you to complete the tutorial on "Basic datatypes and operators".
00:27 A dictionary in general, is designed to look up for meanings of words.
00:35 Similarly, Python dictionary is also designed to look up for a specific key and retrieve the corresponding value.
00:43 Dictionaries are data structures that provide key-value mappings.
00:47 Dictionaries are similar to lists except that instead of the values having integer indexes, dictionaries have keys or strings as indexes.
00:58 We start our ipython interpreter as, ipython
01:07 Let us start by creating an empty dictionary.
01:12 Type the following in your IPython interpreter,mt underscore dict = closing curly brackets
01:25 Notice that unlike lists, curly braces are used to define a dictionary
01:33 Now let us see how to create a non-empty dictionary,
01:37 so type extensions = open curly brackets in single quotes jpg colon 'JPEG Image' comma 'py' colon 'Python script' comma

'html' colon 'Html document' comma pdf colon Portable Document Format close curly brackets

02:08 Notice that each key-value pair is separated by a comma.
02:17 and each key value are separated using a colon.
02:23 Here, we have defined four entries in the dictionary extensions.
02:29 The keys are jpg comma py comma html comma and pdf.
02:36 Simply type,extensions in the interpreter to see the content of the dictionary.
02:40 So type extensions.
02:45 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.
02:53 Like lists, the elements in a dictionary can be accessed using the index, here the index is the key.
03:06 We type, print extensions in closing brackets in single quotes jpg.
03:25 NOW It printed JPEG Image. And now type print extensions within square brackets zip.
03:42 Well it gave us an error, saying that the key 'zip' is not in the dictionary.
03:48 So Pause here for some time and try few more keys.
03:52 Also try jpg in capital letters.
03:58 <continue from paused state Well that was about creating dictionaries, now how do we add or delete items?
04:09 We can add new items into dictionaries as,
04:13 Type extensions within square brackets in single quotes cpp is equal to in single quotes C++ then code.
04:36 and delete items using the del keyword as, type del space extensions and in square brackets and single quotes pdf.
04:51 Let us check the content of the dictionary now,
04:54 So type extensions.
04:57 So the changes have been made.
04:59 let us try one more thing, type extensions within square brackets and in single quotes cpp is equal to in single quote C++ and source code. then type again extensions.
05:21 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.
05:29 Now let us learn how to check if a particular key is present in the dictionary.
05:33 For that we can use the method in,
05:37 So type within single quotes py in extensions.
05:45 Then type odt in extensions.
05:53 It will return True if the key is found in the dictionary, and will return False if key is not present.
06:00 Note that we can check only for container-ship of keys in dictionaries and not values.
06:07 Now let us see how to retrieve the keys and values.
06:10 We can use the method keys() for getting a list of the keys in a particular dictionary and the method values() for getting a list of values.
06:20 Let us try them, type extensions dot key closing brackets.
06:31 It returned the list of keys in the dictionary extensions.
06:35 And now the other one is extensions dot values and closing brackets.
06:42 It returned the list of values in the dictionary.
06:45 Pause the video here, try out the following exercise and resume the video.
06:49 Print the keys and values in the dictionary one by one.
06:54 Now Switch to terminal for solution.
06:58 Type for each in extensions dot keys closing brackets colon then, print each comma within double quotes hyphen hyphen greater symbol, extensions and in square brackets each.
07:35 This brings us to the end of this tutorial.
07:39 In this tutorial, we have learn't to,
07:41 Create dictionaries namely -- - empty dictionaries - dictionaries with data.
07:45 Access elements in the dictionaries using the keys.
07:49 Add elements to a dictionary by assigning a key value.
07:55 Delete elements from a dictionary by using the function del
08:00 Retrieve the keys and values by using the methods .keys() and.values() respectively.
08:06 Iterate over elements of a dictionary using a for loop.
08:11 Here are some self assessment questions for you to solve
08:15 First one, Container-ship of values can be checked in a python dictionary - true or false.
08:22 Second one is, Consider the python dictionary x is equal to within curly brackets 'a' colon ['a','b','c'], 'b' colon (1, 2, 3), 1 colon then again another curly braces 1 colon 'one' comma 2 colon 'two' comma 10 colon within curly brackets 10 colon 'ten', 11 colon 'eleven' and close the curly brackets.
08:52 What will the following code return?
08:57 (1, 2, 3) in x.values(). True. False
09:05 Then container-ship of values cannot be checked in dictionaries
09:10 The dictionary is invalid
09:13 So Lets look at the answers,
09:16 The answer of first one, False.
09:19 Container-ship of only keys can be checked in a python dictionary.
09:27 Second one is, True
09:31 Hope you have enjoyed this tutorial and found it useful.
09:35 Thank you!

Contributors and Content Editors

Gaurav, Minal, PoojaMoolya, Sneha