Difference between revisions of "Python/C3/Getting-started-with-lists/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with '{| border=1 !Timing !Narration |- | 0:00 | Hello friends and welcome to the tutorial on "Getting started with lists". |- | 0:06 | In this tutorial we will be getting acquainted…')
 
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{| border=1
 
{| border=1
!Timing
+
|'''Time'''
!Narration
+
|'''Narration'''
 
|-
 
|-
| 0:00
+
| 00:00
 
| Hello friends and welcome to the tutorial on "Getting started with lists".
 
| Hello friends and welcome to the tutorial on "Getting started with lists".
  
 
|-
 
|-
0:06
+
00:06
 
| In this tutorial we will be getting acquainted with a python data structure called lists. At the end of this tutorial, you will be able to,
 
| In this tutorial we will be getting acquainted with a python data structure called lists. At the end of this tutorial, you will be able to,
 
+
Create lists
# Create lists
+
Access list elements
# Access list elements
+
Append elements to lists
# Append elements to lists
+
Delete elements from lists
# Delete elements from lists
+
  
 
|-
 
|-
0:23
+
00:23
 
| So now, List is a compound data type, it can contain data of mutually different data types.
 
| So now, List is a compound data type, it can contain data of mutually different data types.
  
 
|-
 
|-
| 0:32
+
| 00:32
 
| List is also a sequence data type where all the elements are arranged in a specific order.
 
| List is also a sequence data type where all the elements are arranged in a specific order.
  
 
|-
 
|-
|0:36
+
|00:36
 
|Start the ipython interpreter and first create an empty list with no elements.
 
|Start the ipython interpreter and first create an empty list with no elements.
  
 
|-
 
|-
|0:41
+
|00:41
 
|In command ipython.Then type empty is equal to square brackets.
 
|In command ipython.Then type empty is equal to square brackets.
  
 
|-
 
|-
|0:53
+
|00:53
|Then type within brackets empty.
+
|Then type empty() within brackets empty.
  
 
|-
 
|-
0:59
+
00:59
 
| This is an empty list without any elements.
 
| This is an empty list without any elements.
  
 
|-
 
|-
|1:03
+
|01:03
|Lets define a non-empty list as nonempty is equal to  within square brackets and in single quotes spam comma within single quotes eggs comma 100 comma  1.234]  
+
|Lets define a non-empty list as non empty is equal to  within square brackets and in single quotes spam comma within single quotes eggs comma 100 comma  1.234]  
  
 
|-
 
|-
| 1:24
+
| 01:24
 
| Thus, the simplest way of creating a list is typing out a sequence of comma-separated values (or items) between two square brackets.
 
| Thus, the simplest way of creating a list is typing out a sequence of comma-separated values (or items) between two square brackets.
  
 
|-
 
|-
|1:34
+
|01:34
 
| As we can see, lists can contain different kinds of data.
 
| As we can see, lists can contain different kinds of data.
  
 
|-
 
|-
|1:37
+
|01:37
 
| In the previous example 'spam' and 'eggs' are strings whereas 100 and 1.234 are integer and float respectively.
 
| In the previous example 'spam' and 'eggs' are strings whereas 100 and 1.234 are integer and float respectively.
  
 
|-
 
|-
|1:48
+
|01:48
 
| Thus, we can put elements of different data types in lists including lists itself.
 
| Thus, we can put elements of different data types in lists including lists itself.
  
 
|-
 
|-
|1:54
+
|01:54
 
| This property makes lists heterogeneous data structures.
 
| This property makes lists heterogeneous data structures.
  
 
|-
 
|-
|1:59
+
|01:59
 
| Let us include a list within a list.
 
| Let us include a list within a list.
  
 
|-
 
|-
| 2:02  
+
| 02:02  
| <nowiki>We access an element of a list using its corresponding index. </nowiki>
+
| We access an element of a list using its corresponding index.  
  
 
|-
 
|-
|2:07
+
|02:07
|So type in command listinlist is equal to square brackets [4,2,3,4],'and', 1, 2, 3, 4.
+
|So type in command non empty,then type  listinlist is equal to square brackets [4,2,3,4],'and', 1, 2, 3, 4.
  
 
|-
 
|-
|2:41
+
|02:41
|So now we can access an element of a list using its corresponding index.
+
|So now we can access an element of a list using corresponding index.
 
   
 
   
 
|-
 
|-
|2:49
+
|02:49
 
|Index of the first element of a list is 0.  
 
|Index of the first element of a list is 0.  
  
 
|-
 
|-
|2:53
+
|02:53
|<nowiki>So for the list nonempty, nonempty[0] gives the first element, nonempty[1] the second element and so on and nonempty[3] the last element.</nowiki>
+
|So for the list nonempty, nonempty[0] gives the first element, nonempty[1] the second element and so on and nonempty[3] the last element.So type in command non empty within [0] then again nonempty[1] then nonempty[3]
  
 
|-
 
|-
| 3:23
+
| 03:23
 
| 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.
  
 
|-
 
|-
|3:28
+
|03:28
|<nowiki>What happens when you do nonempty[-1].</nowiki>
+
|What happens when you do nonempty[-1].
  
 
|-
 
|-
|3:34
+
|03:34
 
|YOu can switch to terminal and type nonempty -1 in square brackets.
 
|YOu can switch to terminal and type nonempty -1 in square brackets.
  
 
|-
 
|-
| 3:44
+
| 03:44
 
| As you can see you get the data of last element which is 1.234.
 
| As you can see you get the data of last element which is 1.234.
  
 
|-
 
|-
3:53
+
03:53
 
| In python negative indices are used to access elements from the end.
 
| In python negative indices are used to access elements from the end.
  
 
|-
 
|-
| 3:58
+
| 03:58
| So, -1 gives the last element which is the 4th element , -2 gives second element to last and -4 gives the fourth from the last which, in this case, is the first element.
+
| So, -1 gives the last element which is the 4th element , -2 gives second element to last and -4 gives the fourth from the last which, in this case, is the element first .
  
 
|-
 
|-
|4:15
+
|04:15
 
|So type nonempty -1 nonempty[-2] then nonempty -4.
 
|So type nonempty -1 nonempty[-2] then nonempty -4.
  
 
|-
 
|-
| 4:24
+
| 04:24
| We can also append elements to the end of a list using the <tt>append</tt> function.
+
| We can also append elements to the end of a list using the append function.
  
 
|-
 
|-
|4:28
+
|04:28
 
|So type nonempty dot append within brackets and single quotes onemore.
 
|So type nonempty dot append within brackets and single quotes onemore.
  
 
|-
 
|-
|4:41
+
|04:41
 
|We can see an error  
 
|We can see an error  
  
 
|-
 
|-
|4:46
+
|04:46
 
|Then type nonempty ; then type nonempty dot append within brackets 6.
 
|Then type nonempty ; then type nonempty dot append within brackets 6.
  
 
|-
 
|-
|5:09
+
|05:09
 
|then again nonempty.
 
|then again nonempty.
  
 
|-
 
|-
|5:15
+
|05:15
 
| Please, pause the video here, do the exercise and then continue.
 
| Please, pause the video here, do the exercise and then continue.
  
 
|-
 
|-
|5:21
+
|05:21
| 1. What is the syntax to get the element 'and' in the list,listinlist ?
+
|What is the syntax to get the element 'and' in the list,listinlist ?
  
 
|-
 
|-
|5:29
+
|05:29
|2. How would you get 'and' using negative indices?
+
|How would you get 'and' using negative indices?
 
+
 
+
  
 
|-
 
|-
| 5:34
+
| 05:34
 
| So, the solution is on your screen
 
| So, the solution is on your screen
  
 
|-
 
|-
| 5:38
+
| 05:38
 
|As we can see nonempty is appended with 'onemore' and 6 at the end.
 
|As we can see nonempty is appended with 'onemore' and 6 at the end.
  
 
|-
 
|-
| 5:45
+
| 05:45
 
| Let us move further.  
 
| Let us move further.  
  
 
|-
 
|-
|5:47
+
|05:47
|We can use <tt>len</tt> function to check the number of elements in the list.
+
|We can use len function to check the number of elements in the list.
  
 
|-
 
|-
|5:50
+
|05:50
 
| Let us find out the length of the list 'nonempty'.
 
| Let us find out the length of the list 'nonempty'.
  
 
|-
 
|-
|5:54
+
|05:54
 
|So type in command len within brackets nonempty .
 
|So type in command len within brackets nonempty .
  
 
|-
 
|-
6:05
+
06:05
 
| Just like we can append elements to a list, we can also remove them.  
 
| Just like we can append elements to a list, we can also remove them.  
  
 
|-
 
|-
|6:08
+
|06:08
|There are two ways of doing it. One is by using index.
+
|There are two ways of doing it. One is by using index.We will try let type del{nonempty[1]}
  
 
|-
 
|-
|6:12
+
|06:12
 
|So type del within brackets nonempty and square brackets 1.  
 
|So type del within brackets nonempty and square brackets 1.  
  
 
|-
 
|-
6:26
+
06:26
| The function <tt>del</tt> deletes the element at index 1, i.e the second element of the list, 'eggs'.
+
|The function del deletes the element at index 1, i.e the second element of the list, 'eggs'.
  
 
|-
 
|-
|6:34
+
|06:34
 
|The other way is removing element by content.
 
|The other way is removing element by content.
  
 
|-
 
|-
|6:37
+
|06:37
 
| Lets say one wishes to delete 100 from nonempty list.
 
| Lets say one wishes to delete 100 from nonempty list.
  
 
|-
 
|-
|6:41
+
|06:41
|For this, one could use the function <tt>remove</tt>.
+
|For this, one could use the function remove. So type nonempty.remove (100)
  
 
|-
 
|-
6:55
+
06:55
 
| But what if there were two 100's.
 
| But what if there were two 100's.
  
 
|-
 
|-
|6:57
+
|06:57
 
| To check that lets do a small experiment.
 
| To check that lets do a small experiment.
  
 
|-
 
|-
|7:01
+
|07:01
|Now, in command nonempty dot append within brackets and single quotes spam.
+
|Now, in command nonempty dot append within brackets in single quotes spam.
  
 
|-
 
|-
|7:11
+
|07:11
 
| Then type nonempty.
 
| Then type nonempty.
  
 
|-
 
|-
|7:15
+
|07:15
|Then type nonempty dot remove within brackets and single quotes spam; then type nonempty for the output.
+
|Then type nonempty dot remove within brackets in single quotes spam; then type nonempty for the output.
  
 
|-
 
|-
| 7:29
+
| 07:29
| If we now check, we will see that the first occurence 'spam' is removed and therefore the function ''remove'' removes the first occurence of the element in the sequence and leaves others untouched.
+
| If we now check, we will see that the first occurrence 'spam' is removed and therefore the function ''remove'' removes the first occurence of the element in the sequence and leaves others untouched.
  
 
|-
 
|-
|7:39
+
|07:39
|One should remember this, that while <tt>del</tt> removes by index number, ''remove'' removes on the basis of content being passed on.
+
|One should remember this, that while del removes by index number, ''remove'' removes on the basis of content being passed on.
  
 
|-
 
|-
|7:50
+
|07:50
 
| Let us take an example.
 
| Let us take an example.
  
 
|-
 
|-
7:53
+
07:53
| <nowiki>del gives us [1,2,3].</nowiki>
+
|Type del gives us [1,2,3].
  
 
|-
 
|-
|7:59
+
|07:59
|So type on the terminal k is equal to 1,2 ,1,3 and then type del within brackets and square brackets k and square brackets 2.
+
|So type on the terminal k is equal to 1,2 ,1,3 and then type del within brackets and square brackets k then square brackets 2.
  
 
|-
 
|-
8:25
+
08:25
| <nowiki>remove will give us [2,1,3].  
+
| remove will give us [2,1,3].  
  
 
|-
 
|-
|8:29
+
|08:29
|Since it deletes the first occurrence of what is returned by x[2] which is 1.</nowiki>
+
|Since it deletes the first occurrence of what is returned by x[2] which is 1.
  
 
|-
 
|-
|8:37
+
|08:37
|So type k dot remove and in brackets x and square brackets 2.
+
|So type k dot remove and in brackets x then square brackets 2.
  
 
|-
 
|-
|8:59
+
|08:59
 
|As we have seen an error we have to change x of 2 to k of 2.
 
|As we have seen an error we have to change x of 2 to k of 2.
  
 
|-
 
|-
| 9:09
+
| 09:09
| Pause the video here, try out the following exercise and resume the video.
+
| Pause the video here, try out the following exercise and resume
 
+
 
|-
 
|-
|9:14
+
|09:14
|1. Remove the third element from the list, listinlist.
+
|Remove the third element from the list, listinlist.
  
 
|-
 
|-
|9:19
+
|09:19
|2. Remove 'and' from the list, listinlist.
+
|Remove 'and' from the list, listinlist.
 
+
 
+
  
 
|-
 
|-
|9:24
+
|09:24
 
| The solution is on your screen.
 
| The solution is on your screen.
  
 
|-
 
|-
|9:29
+
|09:29
| This brings us to the end of this tutorial.
+
| This brings us to the end of this tutorial. In this tutorial, we have learnt to, Create lists, Access lists using their index numbers, Append elements to list using the function  append
 
+
 
|-
 
|-
| 9:30
+
|09:40
| In this tutorial, we have learnt to, Create lists, Access lists using their index numbers, Append elements to list using the function <tt>append</tt>.
+
| Delete Element from lists by specifying the index number of the element to be deleted in the del function.
  
 
|-
 
|-
|9:40
+
|09:47
| Delete Element from lists by specifying the index number of the element to be deleted in the <tt>del</tt> function.
+
|Then,Delete element from list by content using remove  function and final one is Find out the list length using  len  function.
  
 
|-
 
|-
|9:47
+
| 09:59
|Then,Delete element from list by content using <tt>remove</tt> function and final one is Find out the list length using <tt>len</tt> function.
+
 
+
|-
+
| 9:59
+
 
| Here are some self assessment questions for you to solve
 
| Here are some self assessment questions for you to solve
  
 
|-
 
|-
 
|10:02
 
|10:02
|1. How do you create an empty list?
+
|How do you create an empty list?
  
 
|-
 
|-
 
|10:05
 
|10:05
|2. Can you have a list inside a list ?
+
|Can you have a list inside a list ?
  
 
|-
 
|-
 
|10:09
 
|10:09
|3. How would you access the end of a list without finding its length?
+
|How would you access the end of a list without finding its length?
 
+
 
+
  
 
|-
 
|-
Line 315: Line 303:
 
|-
 
|-
 
|10:18
 
|10:18
|1. We create an empty list just by leaving the space inside the square brackets empty.<br/>  <nowiki>empty=[]</nowiki>
+
|We create an empty list just by leaving the space inside the square brackets empty.empty=[]
  
 
|-
 
|-
 
|10:30
 
|10:30
|2. Yes.
+
| Yes.
  
 
|-
 
|-
Line 327: Line 315:
 
|-
 
|-
 
|10:44
 
|10:44
| Here is an example<br/>  <nowiki>list_in_list=[2.3,[2,4,6],'string,'all datatypes can be there']</nowiki>
+
| Here is an example list_in_list=[2.3,[2,4,6],'string,'all datatypes can be there']
  
 
|-
 
|-
 
|10:56
 
|10:56
|3. Using negative indices, we can access the list from the end using negative indices.
+
| Using negative indices, we can access the list from the end using negative indices.
  
 
|-
 
|-
 
|11:04
 
|11:04
| This is an example<br/>  <nowiki>nonempty = ['spam', 'eggs', 100, 1.234]</nowiki> <nowiki>nonempty[-1]</nowiki>
+
| This is an example nonempty = ['spam', 'eggs', 100, 1.234] nonempty[-1]
  
 
|-
 
|-

Latest revision as of 11:18, 27 March 2017

Time Narration
00:00 Hello friends and welcome to the tutorial on "Getting started with lists".
00:06 In this tutorial we will be getting acquainted with a python data structure called lists. At the end of this tutorial, you will be able to,

Create lists Access list elements Append elements to lists Delete elements from lists

00:23 So now, List is a compound data type, it can contain data of mutually different data types.
00:32 List is also a sequence data type where all the elements are arranged in a specific order.
00:36 Start the ipython interpreter and first create an empty list with no elements.
00:41 In command ipython.Then type empty is equal to square brackets.
00:53 Then type empty() within brackets empty.
00:59 This is an empty list without any elements.
01:03 Lets define a non-empty list as non empty is equal to within square brackets and in single quotes spam comma within single quotes eggs comma 100 comma 1.234]
01:24 Thus, the simplest way of creating a list is typing out a sequence of comma-separated values (or items) between two square brackets.
01:34 As we can see, lists can contain different kinds of data.
01:37 In the previous example 'spam' and 'eggs' are strings whereas 100 and 1.234 are integer and float respectively.
01:48 Thus, we can put elements of different data types in lists including lists itself.
01:54 This property makes lists heterogeneous data structures.
01:59 Let us include a list within a list.
02:02 We access an element of a list using its corresponding index.
02:07 So type in command non empty,then type listinlist is equal to square brackets [4,2,3,4],'and', 1, 2, 3, 4.
02:41 So now we can access an element of a list using corresponding index.
02:49 Index of the first element of a list is 0.
02:53 So for the list nonempty, nonempty[0] gives the first element, nonempty[1] the second element and so on and nonempty[3] the last element.So type in command non empty within [0] then again nonempty[1] then nonempty[3]
03:23 Pause the video here, try out the following exercise and resume the video.
03:28 What happens when you do nonempty[-1].
03:34 YOu can switch to terminal and type nonempty -1 in square brackets.
03:44 As you can see you get the data of last element which is 1.234.
03:53 In python negative indices are used to access elements from the end.
03:58 So, -1 gives the last element which is the 4th element , -2 gives second element to last and -4 gives the fourth from the last which, in this case, is the element first .
04:15 So type nonempty -1 nonempty[-2] then nonempty -4.
04:24 We can also append elements to the end of a list using the append function.
04:28 So type nonempty dot append within brackets and single quotes onemore.
04:41 We can see an error
04:46 Then type nonempty ; then type nonempty dot append within brackets 6.
05:09 then again nonempty.
05:15 Please, pause the video here, do the exercise and then continue.
05:21 What is the syntax to get the element 'and' in the list,listinlist ?
05:29 How would you get 'and' using negative indices?
05:34 So, the solution is on your screen
05:38 As we can see nonempty is appended with 'onemore' and 6 at the end.
05:45 Let us move further.
05:47 We can use len function to check the number of elements in the list.
05:50 Let us find out the length of the list 'nonempty'.
05:54 So type in command len within brackets nonempty .
06:05 Just like we can append elements to a list, we can also remove them.
06:08 There are two ways of doing it. One is by using index.We will try let type del{nonempty[1]}
06:12 So type del within brackets nonempty and square brackets 1.
06:26 The function del deletes the element at index 1, i.e the second element of the list, 'eggs'.
06:34 The other way is removing element by content.
06:37 Lets say one wishes to delete 100 from nonempty list.
06:41 For this, one could use the function remove. So type nonempty.remove (100)
06:55 But what if there were two 100's.
06:57 To check that lets do a small experiment.
07:01 Now, in command nonempty dot append within brackets in single quotes spam.
07:11 Then type nonempty.
07:15 Then type nonempty dot remove within brackets in single quotes spam; then type nonempty for the output.
07:29 If we now check, we will see that the first occurrence 'spam' is removed and therefore the function remove removes the first occurence of the element in the sequence and leaves others untouched.
07:39 One should remember this, that while del removes by index number, remove removes on the basis of content being passed on.
07:50 Let us take an example.
07:53 Type del gives us [1,2,3].
07:59 So type on the terminal k is equal to 1,2 ,1,3 and then type del within brackets and square brackets k then square brackets 2.
08:25 remove will give us [2,1,3].
08:29 Since it deletes the first occurrence of what is returned by x[2] which is 1.
08:37 So type k dot remove and in brackets x then square brackets 2.
08:59 As we have seen an error we have to change x of 2 to k of 2.
09:09 Pause the video here, try out the following exercise and resume
09:14 Remove the third element from the list, listinlist.
09:19 Remove 'and' from the list, listinlist.
09:24 The solution is on your screen.
09:29 This brings us to the end of this tutorial. In this tutorial, we have learnt to, Create lists, Access lists using their index numbers, Append elements to list using the function append
09:40 Delete Element from lists by specifying the index number of the element to be deleted in the del function.
09:47 Then,Delete element from list by content using remove function and final one is Find out the list length using len function.
09:59 Here are some self assessment questions for you to solve
10:02 How do you create an empty list?
10:05 Can you have a list inside a list ?
10:09 How would you access the end of a list without finding its length?
10:15 And the answers,
10:18 We create an empty list just by leaving the space inside the square brackets empty.empty=[]
10:30 Yes.
10:34 List can contain all the other data types, including list.
10:44 Here is an example list_in_list=[2.3,[2,4,6],'string,'all datatypes can be there']
10:56 Using negative indices, we can access the list from the end using negative indices.
11:04 This is an example nonempty = ['spam', 'eggs', 100, 1.234] nonempty[-1]
11:15 Hope you have enjoyed this tutorial and found it useful.
11:19 Thank you!

Contributors and Content Editors

Gaurav, Minal, PoojaMoolya, Sneha