1 00:00:02,090 --> 00:00:11,400 Now let's move on to lists lists are very similar to a string except that each element can be of any 2 00:00:11,400 --> 00:00:21,970 type in the strings each element was a character but in lists each element can be of any type so the 3 00:00:21,980 --> 00:00:22,810 final list. 4 00:00:22,870 --> 00:00:25,320 We have to use the square records. 5 00:00:25,480 --> 00:00:31,150 So if I write one and one is our a variable name then in the square right. 6 00:00:31,270 --> 00:00:33,010 If I write 1 2 3 4 7 00:00:37,820 --> 00:00:42,870 1 2 3 4 5 and run this everyone is a want list. 8 00:00:44,110 --> 00:00:45,220 Check right. 9 00:00:45,240 --> 00:00:45,660 Babe 10 00:00:49,680 --> 00:00:59,580 L1 are destroying that type of L1 characters list to print all its value. 11 00:00:59,620 --> 00:01:00,220 We. 12 00:01:00,510 --> 00:01:01,290 Print L1 13 00:01:07,840 --> 00:01:10,690 and we are getting all the values that anyone is containing 14 00:01:13,690 --> 00:01:15,100 just like strings. 15 00:01:15,100 --> 00:01:20,240 We can also use the same slicing techniques to manipulate lists. 16 00:01:20,290 --> 00:01:34,990 So if I write a one square record zero this will give me an element present does the location which 17 00:01:34,990 --> 00:01:35,930 is one. 18 00:01:35,980 --> 00:01:39,280 So here one is at locations Zero. 19 00:01:39,400 --> 00:01:41,210 Who is their location. 20 00:01:41,470 --> 00:01:49,270 1 3 is their location 2 4 3 favorite for just like string. 21 00:01:49,270 --> 00:01:54,020 I can use colon to select multiple elements. 22 00:01:54,220 --> 00:02:01,680 If I write 0 4 then 3 it will give me the first three elements here. 23 00:02:01,760 --> 00:02:03,340 The location 3 is excluded. 24 00:02:03,410 --> 00:02:11,500 So I will get elements present at locations Zero location one location all three is excluded. 25 00:02:11,810 --> 00:02:16,550 Just like slicing in the strings you can also use steps. 26 00:02:16,730 --> 00:02:25,400 So if I write L1 now if I want to select all the elements I will just state for them. 27 00:02:25,830 --> 00:02:27,920 Then I will write another. 28 00:02:28,300 --> 00:02:32,400 So first argument was for the starting location. 29 00:02:32,410 --> 00:02:38,360 Second argument was for the stopping location and the third argument is for the steps. 30 00:02:38,530 --> 00:02:43,840 We are not giving a starting and stopping location since we want all the elements. 31 00:02:43,840 --> 00:02:46,160 And now we are defining this step as two. 32 00:02:46,480 --> 00:02:49,750 So it will give me all the elements of my list. 33 00:02:52,130 --> 00:02:57,780 So again it is ignoring when for instance we decided to step off to 34 00:03:02,040 --> 00:03:06,820 it is not necessary for list to have all the elements of same type. 35 00:03:07,020 --> 00:03:10,610 You can assign different types of element in a single list. 36 00:03:10,620 --> 00:03:20,720 So if I write a to equate to square record one former if I want to create a string I will write and 37 00:03:20,720 --> 00:03:32,060 double quotation a comma if I want to provide floating point numbers I will write 1.0 and if I run this 38 00:03:34,610 --> 00:03:40,510 my 2 is created under that type of my first element is in second element to the string. 39 00:03:40,630 --> 00:03:42,730 The tone at the moment is. 40 00:03:44,170 --> 00:03:47,920 But we can say on this in that single list as well. 41 00:03:52,080 --> 00:03:55,860 So if we want to check we can check using the type operator. 42 00:03:56,050 --> 00:04:02,580 If I type now inside a do I want the data type of first element. 43 00:04:02,600 --> 00:04:10,230 So I will write zero and they did the end because 1 is lower and 0 if I write type 44 00:04:14,160 --> 00:04:15,220 square one. 45 00:04:17,800 --> 00:04:20,110 Which is string because of what it is. 46 00:04:20,110 --> 00:04:25,100 Double quotation and we have created a string as a string right. 47 00:04:27,230 --> 00:04:28,550 What I do is a list. 48 00:04:28,560 --> 00:04:33,420 That's why we just state type of I do it for the string us list. 49 00:04:35,860 --> 00:04:40,270 We can also provide list as an element of another list. 50 00:04:40,270 --> 00:04:42,850 So if we write L3 equate to 51 00:04:46,110 --> 00:04:46,660 a do 52 00:04:49,330 --> 00:04:55,540 Cuomo 1 Omar 2.0 53 00:04:59,220 --> 00:05:00,350 if we've done this come. 54 00:05:00,560 --> 00:05:04,580 So we have quite a list as you to list inside L3. 55 00:05:04,850 --> 00:05:06,140 So if we print L3 56 00:05:09,420 --> 00:05:17,750 here our first element is a list which is a true and never second element is in and third element this 57 00:05:17,930 --> 00:05:18,340 load. 58 00:05:19,230 --> 00:05:29,770 So just to check if we write type of and three former zero. 59 00:05:30,120 --> 00:05:36,150 This is joining us as list because we have provided you two inside of L3. 60 00:05:36,240 --> 00:05:41,210 Now we have mentioned how to select the first element of L3. 61 00:05:41,370 --> 00:05:46,120 We can just write L3 and then record we can write 0. 62 00:05:46,160 --> 00:05:48,340 This will give us the first element. 63 00:05:48,620 --> 00:05:50,750 My first element is a list. 64 00:05:51,050 --> 00:05:54,440 So how to select first element of that list. 65 00:05:54,440 --> 00:05:56,240 We can write L3 66 00:05:59,160 --> 00:06:00,270 and square the record. 67 00:06:00,270 --> 00:06:03,390 I will first rate 0 right now. 68 00:06:03,390 --> 00:06:07,670 I am accessing my first element which is the list. 69 00:06:07,760 --> 00:06:15,880 Now if I want the second element of this list I will write in the squared record one if I done this 70 00:06:15,880 --> 00:06:24,040 Come on it couldn't give us the character in these types of lists are called nested lists because we 71 00:06:24,040 --> 00:06:28,190 have lists inside the list. 72 00:06:28,350 --> 00:06:33,500 Now you can also create lists using special functions such as range. 73 00:06:33,510 --> 00:06:44,490 So if I write list and then record and write Grange in Grange I have to provide the starting point stopping 74 00:06:44,490 --> 00:06:45,810 point in this step. 75 00:06:46,260 --> 00:06:57,790 So if I provide zero as my starting point then as my stopping point and step as to and if I run this 76 00:06:58,270 --> 00:07:09,560 range will provide me an output of 0 2 4 6 8 and I'm using list keyword to convert this output and the 77 00:07:09,560 --> 00:07:16,730 form off list so we can create another variable for equate to 78 00:07:24,160 --> 00:07:33,610 range 0 2 10 with step 2. 79 00:07:33,650 --> 00:07:36,070 Now if we bring out a variable L for 80 00:07:39,840 --> 00:07:48,720 we can see 0 is over for sending my 2 4 to 6 and then 8 if we want it all sorted and then descending 81 00:07:48,720 --> 00:07:51,210 order we'll write for the dots sort. 82 00:07:51,280 --> 00:07:56,590 So do the function and the arguing it is reverse equator grew. 83 00:07:56,790 --> 00:08:02,040 If we don't give this city what's equal to group it will automatically started in ascending order. 84 00:08:02,160 --> 00:08:04,440 What we wanted in descending order. 85 00:08:04,510 --> 00:08:06,500 That's why we are providing argument. 86 00:08:06,510 --> 00:08:07,780 What's equally true. 87 00:08:07,980 --> 00:08:15,880 Now if we check and before you can see a bit sorted in the descending order our first element is 8 which 88 00:08:15,880 --> 00:08:19,630 is the largest and the last element is zero. 89 00:08:19,630 --> 00:08:20,610 This mother said My 90 00:08:23,860 --> 00:08:30,850 if we want to add more elements in our list we can use a pen function. 91 00:08:30,850 --> 00:08:34,120 We'll write for that. 92 00:08:34,160 --> 00:08:34,670 A pen 93 00:08:37,730 --> 00:08:40,140 and then record you mentioned. 94 00:08:40,590 --> 00:08:41,100 Really. 95 00:08:41,170 --> 00:08:43,310 Well here we are writing Ben 96 00:08:46,000 --> 00:08:56,350 this add the value pen at the end of the list as you can see we have Ben at the end of the list if we 97 00:08:56,350 --> 00:09:02,570 want to change value of any element we can just write that element address. 98 00:09:02,580 --> 00:09:07,020 So look for Square Records zero. 99 00:09:07,160 --> 00:09:12,710 This is our first element and we want the value of this element to be three. 100 00:09:12,710 --> 00:09:20,400 So it would equate to three it will automatically change the value of the first element to three. 101 00:09:20,420 --> 00:09:23,420 So earlier it was a non-event Lewis three 102 00:09:26,270 --> 00:09:30,140 if you want to change values off my table elements. 103 00:09:30,140 --> 00:09:42,920 We can write for you want to change the value of second and third so we'll write one more than three. 104 00:09:42,980 --> 00:09:50,040 This means elements second and third since three is not included and one is included. 105 00:09:50,600 --> 00:09:55,060 And then in this square a record we can write the values. 106 00:09:55,060 --> 00:09:57,470 So if we write 5 almost 7 107 00:10:00,660 --> 00:10:06,110 now we are replacing the 6 2 5 4 7 3. 108 00:10:06,180 --> 00:10:16,070 Then this you can see the values are not changed in the way we are creating another list to replace 109 00:10:16,120 --> 00:10:17,570 the elements of this list. 110 00:10:21,860 --> 00:10:29,690 Now if we want to in certain element account is specific index will do this by using a keyword insert. 111 00:10:29,930 --> 00:10:40,060 So if we write for insert and we want to insert this element at the first position so we'll write 0 112 00:10:40,460 --> 00:10:46,310 since 0 either plus or nation will write 15. 113 00:10:46,780 --> 00:10:53,050 So if we write 15 in double quotation this means we are passing this element as a string. 114 00:10:53,050 --> 00:10:59,030 So let's do this. 115 00:10:59,560 --> 00:11:05,710 You can see we have inserted this 15 string at the first violation. 116 00:11:05,720 --> 00:11:11,710 Now all my other elements are shifted by one in space. 117 00:11:11,710 --> 00:11:19,600 Now if we want to remove element of this string we can do this by using who will command first as the 118 00:11:19,870 --> 00:11:20,880 remove function. 119 00:11:20,920 --> 00:11:26,920 And the second is that delete function remove function will remove the value of that element. 120 00:11:27,220 --> 00:11:36,490 So for example if I write removed the code 3 and 4 remove record three it will first search the elements 121 00:11:36,610 --> 00:11:40,340 which have the value three in that case this is the second element. 122 00:11:40,400 --> 00:11:42,750 So delete this second element. 123 00:11:42,890 --> 00:11:43,660 If we run this 124 00:11:46,850 --> 00:11:52,880 whereas if I am using delete it really delete the position of that element. 125 00:11:52,910 --> 00:12:02,430 So for example but for right then I added for and then I have to specify the location. 126 00:12:02,520 --> 00:12:07,320 So if I and I zero that means the first location will be deleted. 127 00:12:07,440 --> 00:12:16,620 So we've done this again and therefore you can see the plane is not on the network we are on the on 128 00:12:16,620 --> 00:12:24,540 the 5 7 2 0 9 10 that making now if you want to know more about lists you can write. 129 00:12:24,540 --> 00:12:35,910 Help help me look you where you can use anywhere you can write and record you can write this if you 130 00:12:35,910 --> 00:12:36,520 run this 131 00:12:39,860 --> 00:12:41,920 you to get all the information out. 132 00:12:42,100 --> 00:12:43,900 We are not going to discuss all the. 133 00:12:45,100 --> 00:12:54,770 And just so quick EP if you want to do more your output just select the set converted to blindly and 134 00:12:54,770 --> 00:12:57,390 then again convert it to court. 135 00:12:57,500 --> 00:13:01,850 Now you're also based on so if you have some large output you can. 136 00:13:01,850 --> 00:13:04,530 You probably want to do this. 137 00:13:05,060 --> 00:13:07,550 Now let's move on to the. 138 00:13:07,570 --> 00:13:11,670 The palace is another data type voided whereby 10 139 00:13:19,180 --> 00:13:26,380 so the police are just like list except that they cannot be modified once created. 140 00:13:26,490 --> 00:13:29,580 That's what we call them immune tables. 141 00:13:29,710 --> 00:13:38,270 So to balance out immune tables and a list is your but so to assign that up. 142 00:13:38,540 --> 00:13:49,640 We use parentheses so for lists we use a square record for doubles we use parentheses if we write even 143 00:13:51,230 --> 00:13:55,310 equation that sentences one comma to 144 00:14:02,250 --> 00:14:11,730 so if you see when we were putting the list there were squared record at the end and they suck but for 145 00:14:11,730 --> 00:14:23,670 the doubles we have parenthesis and we cannot change the values of this elements so just to write if 146 00:14:23,670 --> 00:14:27,180 we want to change the value of this element we can write even 147 00:14:30,070 --> 00:14:40,520 then squared records 0 equal to 5 since this is a table we will get an error while running this. 148 00:14:40,520 --> 00:14:48,080 So you can see the error is double object does not support item assignment you can not change the value 149 00:14:48,080 --> 00:14:59,170 of the apple once created to get the tape of the Stephen Page even you can see the typist double there 150 00:14:59,170 --> 00:15:05,740 are very limited use cases of apples and we will hardly use the apples in our analysis. 151 00:15:05,830 --> 00:15:09,250 Let's move on to the next day today which is dictionary 152 00:15:15,930 --> 00:15:24,930 dictionaries are also like lists except that each element is a key value pair and thus index for assigning 153 00:15:24,930 --> 00:15:29,440 dictionaries is using live records in the list. 154 00:15:29,460 --> 00:15:38,880 We use a squared record in double we use parentheses in dictionaries release college records so in the 155 00:15:38,880 --> 00:15:44,890 list there are indexes starting from 0 1 2 3 4. 156 00:15:44,940 --> 00:15:49,700 Here you can see that you are assigning this indexes on your own. 157 00:15:49,700 --> 00:15:57,580 So for each element you have the assignment index which we call up key and the element is called s value. 158 00:15:57,590 --> 00:16:02,030 That's why we define dictionaries as a collection of key value pairs. 159 00:16:03,020 --> 00:16:12,680 So to assign a variable be one which is our dictionary we'll write where we look at live records now 160 00:16:12,720 --> 00:16:13,150 here. 161 00:16:13,200 --> 00:16:23,750 First we have to write that key he won and then right colon and the value of this scheme which is 1 162 00:16:25,810 --> 00:16:27,020 comma. 163 00:16:27,590 --> 00:16:28,130 You do 164 00:16:33,330 --> 00:16:39,210 so in a list there were index 0 1 2 3 4 this key 1 2 key. 165 00:16:39,220 --> 00:16:41,370 3 are just like indexes 166 00:16:49,080 --> 00:16:50,550 fee this 167 00:16:53,450 --> 00:16:59,020 would be one run this you can see in this. 168 00:16:59,030 --> 00:17:01,910 We were only getting the values in the here. 169 00:17:01,940 --> 00:17:12,000 We are getting first the keys and then the value so if you're one you can see the type of this B1 type 170 00:17:13,170 --> 00:17:19,020 B1 the typist dictionary. 171 00:17:19,070 --> 00:17:29,020 Now if I want to grab the first value I will write B1 and then a squared record I will write even 172 00:17:33,480 --> 00:17:45,050 if it on this you can see for the E given we have a value of once in the list we are using directly 173 00:17:45,050 --> 00:17:53,520 using the indexes such as 0 1 2 3 4 in dictionaries we have to use this D to get the value of that bit 174 00:17:54,060 --> 00:17:54,710 of 175 00:17:57,850 --> 00:18:00,760 so far I tried to write like this. 176 00:18:00,760 --> 00:18:02,580 B1 squared records 0. 177 00:18:02,590 --> 00:18:05,130 That is the first element I will get an error. 178 00:18:05,530 --> 00:18:09,180 I always have to refer this value using the key of this value 179 00:18:15,630 --> 00:18:26,220 so Python also supports conditional statements such as if as or else if and it also supports loops such 180 00:18:26,240 --> 00:18:30,820 as for loop and while loop we are not going to discuss this here. 181 00:18:30,970 --> 00:18:34,760 If you want you can explore this on your own. 182 00:18:35,840 --> 00:18:39,710 If needed we will discuss it in our upcoming lectures.