1 00:00:00,000 --> 00:00:03,300 [no audio] 2 00:00:03,300 --> 00:00:06,000 Friends, here we are going to discuss the very first 3 00:00:06,000 --> 00:00:09,400 data structure of your Python, that is list data structure. 4 00:00:10,400 --> 00:00:13,000 So first let me open my Notepad and I will show you how 5 00:00:13,000 --> 00:00:14,300 to define a list. 6 00:00:15,600 --> 00:00:18,400 So guys any name you can take. Simply 7 00:00:18,400 --> 00:00:20,400 I am taking 'my_list=' 8 00:00:21,700 --> 00:00:23,400 this one, this is an empty list. 9 00:00:24,000 --> 00:00:26,900 So if you want to create any list with some values, right 10 00:00:26,900 --> 00:00:31,100 let me take 'my_list1=', so 11 00:00:31,100 --> 00:00:33,500 [no audio] 12 00:00:33,500 --> 00:00:36,000 you can provide any type of data. 13 00:00:37,100 --> 00:00:43,200 Right. Now, so this is the way how you can define your list. 14 00:00:44,200 --> 00:00:46,100 And guys, the very first thing in your real time, 15 00:00:46,200 --> 00:00:49,000 I mean very important point in your real time from list is 16 00:00:49,000 --> 00:00:53,100 sometimes you need to convert your list into Boolean, right. 17 00:00:53,100 --> 00:00:57,300 You cannot convert your data into some integer, float, or string, 18 00:00:57,300 --> 00:01:01,400 or complex because list data structure is the combination of data. 19 00:01:01,400 --> 00:01:03,400 [no audio] 20 00:01:03,400 --> 00:01:09,500 Right. Fine. Now in case if I convert our data into Boolean 21 00:01:09,500 --> 00:01:11,300 what will happen? Right. 22 00:01:11,600 --> 00:01:16,000 So for that let me take, let me open my command line of Python. 23 00:01:16,000 --> 00:01:19,800 [no audio] 24 00:01:19,800 --> 00:01:21,400 Right. Simply let me copy 25 00:01:22,500 --> 00:01:26,700 this as one list, no. This is empty list. Be clear, empty list. 26 00:01:28,300 --> 00:01:31,000 So if I try to convert empty list, 27 00:01:31,000 --> 00:01:33,300 [no audio] 28 00:01:33,300 --> 00:01:36,900 right, into Boolean, see that, 'False'. 29 00:01:36,900 --> 00:01:39,100 This is very, very important. Empty, 30 00:01:39,500 --> 00:01:42,500 if anything is empty, if you convert into Boolean that is 31 00:01:42,500 --> 00:01:44,900 'False'. Now instead of empty 32 00:01:45,000 --> 00:01:49,300 let's say some random data, right, any data, now if I try to 33 00:01:49,300 --> 00:01:50,500 convert you will get 'True'. 34 00:01:50,800 --> 00:01:53,300 So these two points are very, very important, 35 00:01:53,700 --> 00:01:56,600 okay. So 'bool( 36 00:01:56,600 --> 00:01:58,500 [no audio] 37 00:01:58,500 --> 00:01:59,500 empty_list)' 38 00:01:59,500 --> 00:02:03,000 [no audio] 39 00:02:03,000 --> 00:02:05,000 is equal to 40 00:02:06,600 --> 00:02:07,600 'False', 41 00:02:08,500 --> 00:02:10,600 'bool(non_empty_ 42 00:02:10,600 --> 00:02:12,500 [no audio] 43 00:02:12,500 --> 00:02:13,500 list)' 44 00:02:13,500 --> 00:02:16,000 [no audio] 45 00:02:16,000 --> 00:02:17,200 equals to 'True' 46 00:02:17,500 --> 00:02:19,800 It's very useful case in your real-time, guys. 47 00:02:19,800 --> 00:02:26,400 [no audio] 48 00:02:26,400 --> 00:02:27,400 Okay, fine. 49 00:02:28,300 --> 00:02:29,300 Now guys, 50 00:02:29,300 --> 00:02:33,900 [no audio] 51 00:02:33,900 --> 00:02:38,800 you know the string operations with the index values, or based 52 00:02:38,800 --> 00:02:40,800 on index values in your string 53 00:02:41,000 --> 00:02:44,500 you are taking, you are displaying particular 54 00:02:45,700 --> 00:02:47,000 character from your string. 55 00:02:47,100 --> 00:02:50,100 Let's say I have a word called 56 00:02:50,100 --> 00:02:51,000 "hello". Already 57 00:02:51,000 --> 00:02:54,100 we know this, just I am recollecting that concept. "hello". 58 00:02:54,800 --> 00:02:57,500 So once if you define your string in this way, what will 59 00:02:57,500 --> 00:03:01,100 happen? Your Python will assign the index value for "h" is 0, 60 00:03:01,100 --> 00:03:05,100 the "e" is for one, second "l", third "l", 61 00:03:05,100 --> 00:03:07,300 and then fourth, right? 62 00:03:07,600 --> 00:03:09,000 So five let us are there, 63 00:03:10,300 --> 00:03:14,200 0 to 4 indexes are there in a positive way, or in a negative 64 00:03:14,200 --> 00:03:21,300 way - 1, - 2, - 3, - 4, and then -5. So you can go with the 65 00:03:21,300 --> 00:03:23,200 negative or positive. 66 00:03:24,500 --> 00:03:29,000 Right. So these are the index values for your strings. The same way 67 00:03:29,000 --> 00:03:30,600 whenever if you define a list, 68 00:03:31,700 --> 00:03:34,900 for list of values also Python will assign some index values. 69 00:03:35,300 --> 00:03:41,700 Let's say this is your list then 3 is at index 0, 2 is at 70 00:03:41,700 --> 00:03:46,500 index 1, 4 is at index 3, sorry 2, this entire thing is one 71 00:03:46,500 --> 00:03:47,900 data in your list. 72 00:03:48,300 --> 00:03:51,900 This is at index 3, and this is at index 4. 73 00:03:51,900 --> 00:03:54,000 [no audio] 74 00:03:54,000 --> 00:03:55,400 Right. I will do one thing. 75 00:03:56,700 --> 00:03:58,300 Even negative way also, 76 00:03:58,500 --> 00:03:59,900 so this is at -1, 77 00:04:00,900 --> 00:04:07,100 this is at -2, 4 is at -3, 2 is at -4, and 78 00:04:07,100 --> 00:04:08,600 then 5 is at -5. 79 00:04:10,000 --> 00:04:12,700 I will take, I will write a simple Python Script to give the 80 00:04:12,700 --> 00:04:17,300 clarity on this list with index operations. 81 00:04:17,700 --> 00:04:20,800 Let me open my Sublime Text. So I am taking this as my 82 00:04:20,800 --> 00:04:25,399 [no audio] 83 00:04:25,399 --> 00:04:27,600 'working_with_a_list'. 84 00:04:27,600 --> 00:04:34,200 [no audio] 85 00:04:34,200 --> 00:04:38,000 Fine. Observe that, first thing, how to print your 86 00:04:38,000 --> 00:04:40,800 list. So I am going to 'print(my_list)', 87 00:04:41,900 --> 00:04:44,400 and I want to see type of your data structure. 88 00:04:44,400 --> 00:04:47,400 Anyway, we know that is a list data structure but through 89 00:04:47,400 --> 00:04:49,000 Python you can find that. 90 00:04:50,600 --> 00:04:52,800 See that, we are getting class as a list. 91 00:04:52,800 --> 00:04:56,500 [no audio] 92 00:04:56,500 --> 00:05:00,100 Right. Fine. Now, let me comment this. 93 00:05:01,800 --> 00:05:06,000 So guys, we are saying that Python is assigning some index 94 00:05:06,000 --> 00:05:08,200 values for your list of values. 95 00:05:09,300 --> 00:05:13,000 So very first value is 3. 3 is at index position 0. Now if 96 00:05:13,000 --> 00:05:16,300 I want to print very first value from your list, or if I 97 00:05:16,300 --> 00:05:19,500 want to take first value from your list, I have to take index 0. 98 00:05:21,200 --> 00:05:23,200 Right. See the output what you are getting, 99 00:05:24,700 --> 00:05:27,300 3. Then I want to get, suppose some "python", 100 00:05:27,300 --> 00:05:28,900 I want to display this output. 101 00:05:29,400 --> 00:05:35,200 So "python" is at one, two, three, fourth value. Fourth value means 102 00:05:35,200 --> 00:05:38,400 index is 3 because you know index starts from 0. 103 00:05:38,800 --> 00:05:43,800 This is 0, 2 is 1, 4 is at 2, and "python" is at 3. 104 00:05:43,800 --> 00:05:45,600 [no audio] 105 00:05:45,600 --> 00:05:48,100 Right. Now I want to get 106 00:05:48,100 --> 00:05:50,100 [no audio] 107 00:05:50,100 --> 00:05:52,600 fourth value, means index is 3. 108 00:05:52,600 --> 00:05:54,400 [no audio] 109 00:05:54,400 --> 00:05:57,600 Yes, you are getting, and this is the way how you can get your 110 00:05:57,600 --> 00:06:01,200 particular value from your list based on positive index values. 111 00:06:01,900 --> 00:06:03,500 Of course, you can also use negative. 112 00:06:03,600 --> 00:06:09,400 Let me take 'print(my_list(-1))'. You know -1 113 00:06:09,400 --> 00:06:10,900 means by default last value. 114 00:06:11,100 --> 00:06:14,100 It may be string, or it may be list, while going forward it 115 00:06:14,100 --> 00:06:15,100 maybe tuple also. 116 00:06:15,100 --> 00:06:18,200 [no audio] 117 00:06:18,200 --> 00:06:21,400 See that. Or let's say I want to get, 118 00:06:21,400 --> 00:06:24,100 [no audio] 119 00:06:24,100 --> 00:06:25,400 from last second value 120 00:06:25,400 --> 00:06:29,800 I want to get. That means index value is -2. If you take 121 00:06:29,800 --> 00:06:31,400 -2 you will get 122 00:06:32,800 --> 00:06:34,800 from last second value. 123 00:06:35,400 --> 00:06:37,800 That's it, right. Now 124 00:06:37,800 --> 00:06:39,600 let me comment all this. 125 00:06:39,600 --> 00:06:41,400 [no audio] 126 00:06:41,400 --> 00:06:43,800 So this is the way how you can access your 127 00:06:43,800 --> 00:06:45,600 [no audio] 128 00:06:45,600 --> 00:06:47,300 list of values 129 00:06:47,300 --> 00:06:49,900 based on index. And one more thing. 130 00:06:50,900 --> 00:06:55,300 See as of now if I run this maybe with -2 or I can take this 131 00:06:55,300 --> 00:06:56,300 also, no problem, 132 00:06:56,300 --> 00:06:58,900 [no audio] 133 00:06:58,900 --> 00:07:02,000 both will give same result, right, because in positive way 134 00:07:02,100 --> 00:07:05,700 your Python index is 3, in negative way index is -2, 135 00:07:06,400 --> 00:07:08,300 right. You can take anything, no problem. 136 00:07:08,300 --> 00:07:10,700 I am taking suppose positive index, and see the output what 137 00:07:10,700 --> 00:07:12,500 you are getting, "python". 138 00:07:13,500 --> 00:07:21,300 Now guys in case if I ask, write a syntax to get from your 139 00:07:21,300 --> 00:07:26,600 list this data and in that I want to display only "y" letter. 140 00:07:28,200 --> 00:07:30,500 If I write something, it has to display only "y". 141 00:07:31,800 --> 00:07:35,600 So first of all you have to get this data. To get that data 142 00:07:35,600 --> 00:07:39,300 already we have a syntax, and that is a string. In string "y" is 143 00:07:39,900 --> 00:07:43,500 second letter. In the output, just observe this output. Now because 144 00:07:43,500 --> 00:07:46,900 of this you are getting this output. In this output "y" is 145 00:07:46,900 --> 00:07:50,700 at second position, means index is 1, 146 00:07:50,700 --> 00:07:54,200 no. Now see that what I am doing, and see what you are 147 00:07:54,200 --> 00:07:55,900 getting by doing this. 148 00:07:57,400 --> 00:08:01,100 You are getting letter "y" because that is a string. Again strings 149 00:08:01,100 --> 00:08:03,200 we can access with the help of index values. 150 00:08:04,300 --> 00:08:07,300 Right. Guys you just try to practice in this way also. 151 00:08:08,800 --> 00:08:12,400 Then, you know in your 152 00:08:14,100 --> 00:08:15,100 list, right, 153 00:08:15,800 --> 00:08:18,500 I mean strings, if I write something like this, 154 00:08:18,800 --> 00:08:20,000 what is the meaning of this? 155 00:08:21,300 --> 00:08:24,300 Entire, I want to get from starting to ending. 156 00:08:24,900 --> 00:08:27,000 This is the way, or simply you can write simply 157 00:08:27,000 --> 00:08:31,300 'my_list' also will work. This also, will give your entire list. 158 00:08:32,200 --> 00:08:37,700 But if I want to print something like first index to last, 159 00:08:37,700 --> 00:08:43,500 '1:'. Now you will get '2, 4, "python", 5.6', because we are mentioning 160 00:08:43,500 --> 00:08:46,900 1 no. 1 means index 1. Index 1 is nothing but 2 data; 2, 161 00:08:46,900 --> 00:08:48,299 4, "python", 5.6 162 00:08:48,299 --> 00:08:50,500 you will get. See the output. 163 00:08:50,500 --> 00:08:52,900 [no audio] 164 00:08:52,900 --> 00:08:57,400 Right. I want to get from 0 to last, same as your, 165 00:08:57,400 --> 00:08:59,200 [no audio] 166 00:08:59,200 --> 00:09:00,700 so guys this syntax, 167 00:09:02,400 --> 00:09:04,900 or let me write all these syntaxes because all 168 00:09:04,900 --> 00:09:06,100 will give same result. 169 00:09:06,100 --> 00:09:11,900 This will be helpful for your online exams. 'my_list' or 'print( 170 00:09:12,800 --> 00:09:15,300 my_list[:])'. 171 00:09:16,300 --> 00:09:18,300 see all the results are same. 172 00:09:18,700 --> 00:09:21,300 So if you want to print a list you can follow any one of this. 173 00:09:23,000 --> 00:09:26,000 That's fine. Now what my intention is, 174 00:09:26,000 --> 00:09:27,700 I want to print something, 175 00:09:29,200 --> 00:09:32,300 like you know, first index to only 176 00:09:32,300 --> 00:09:34,200 [no audio] 177 00:09:34,200 --> 00:09:36,200 three more values. 'print( 178 00:09:37,100 --> 00:09:42,800 my_list', from first index 3 more values. Then 1 + 3, 4. 179 00:09:42,800 --> 00:09:43,800 Then you will get 180 00:09:45,400 --> 00:09:48,300 three more values. From 1, three values. 181 00:09:48,300 --> 00:09:50,300 [no audio] 182 00:09:50,300 --> 00:09:53,400 So guys, you can also consider like 4-1 means range is 183 00:09:53,400 --> 00:09:55,400 3, you are getting three values. That's it. 184 00:09:55,400 --> 00:09:57,700 [no audio] 185 00:09:57,700 --> 00:09:59,600 Okay, fine. 186 00:10:00,000 --> 00:10:02,400 Now this is all about, yeah, we have one more thing. 187 00:10:02,400 --> 00:10:04,400 [no audio] 188 00:10:04,400 --> 00:10:09,900 So guys if I want to change a list of values based on index, 189 00:10:09,900 --> 00:10:15,000 let's say as of now index 0 value is 3 but I want to make 190 00:10:15,000 --> 00:10:19,300 it as some other value then 'my_list[0], I am writing some 191 00:10:19,300 --> 00:10:21,800 45. See the output. 192 00:10:23,100 --> 00:10:24,300 Yeah. After that, I need to print it, 193 00:10:24,300 --> 00:10:25,500 no. Let me print. 194 00:10:25,500 --> 00:10:27,400 [no audio] 195 00:10:27,400 --> 00:10:30,000 Let me comment this line. Because if you print then only you 196 00:10:30,000 --> 00:10:31,400 can see the modification, right? 197 00:10:31,900 --> 00:10:35,700 So after your operation just try to print your list and see 198 00:10:35,700 --> 00:10:36,800 the output what you are getting. 199 00:10:38,000 --> 00:10:40,800 Your index 0 value you are modifying into 45. 200 00:10:42,000 --> 00:10:43,600 Right. Your index value 201 00:10:43,600 --> 00:10:46,700 you're modifying into 45, right? 202 00:10:46,700 --> 00:10:54,500 [no audio] 203 00:10:54,500 --> 00:10:55,500 Fine. 204 00:10:55,500 --> 00:10:57,500 [no audio] 205 00:10:57,500 --> 00:10:59,300 Now, let me comment all these lines. 206 00:10:59,300 --> 00:11:01,900 [no audio] 207 00:11:01,900 --> 00:11:04,600 And one more thing guys because of this data, 208 00:11:04,900 --> 00:11:09,000 I mean this syntax, you are able to modify your list value, 209 00:11:09,900 --> 00:11:15,400 right. You're able to modify your list value. That means lists 210 00:11:15,400 --> 00:11:18,700 are mutable. At any time 211 00:11:18,700 --> 00:11:24,300 you can change your list of values, part of your list, right? 212 00:11:24,300 --> 00:11:28,700 So this is very, very important. So lists are mutable. 213 00:11:28,700 --> 00:11:31,700 [no audio] 214 00:11:31,700 --> 00:11:35,800 And once again, you know strings are immutable. Once if we define 215 00:11:35,800 --> 00:11:40,000 your string, you cannot change the part of your string, but 216 00:11:40,000 --> 00:11:44,200 see that, you can change the part of your list. Because this 217 00:11:44,200 --> 00:11:45,000 operation is allowed, 218 00:11:45,000 --> 00:11:47,800 no. That means you're changing some value in your list, so 219 00:11:47,800 --> 00:11:49,100 lists are mutable. 220 00:11:50,400 --> 00:11:54,700 Fine. So these are based on index, guys, operations on your list, 221 00:11:55,600 --> 00:11:58,100 right? Let me take some other operations. 222 00:11:58,100 --> 00:12:00,400 [no audio] 223 00:12:00,400 --> 00:12:01,700 'my_list', I am taking. 224 00:12:03,100 --> 00:12:05,800 Let's say 3, 4, 5, something, value. 225 00:12:06,300 --> 00:12:07,700 I want to explain the different way. 226 00:12:09,200 --> 00:12:11,400 Fine. Now 227 00:12:13,000 --> 00:12:14,800 first of all, what are the operations available 228 00:12:14,800 --> 00:12:15,500 with your list, 229 00:12:15,600 --> 00:12:19,800 how you come to know that, right? Nothing 230 00:12:19,800 --> 00:12:23,200 is there. Just to go to your command line, Python command line. 231 00:12:23,400 --> 00:12:25,300 Already we have a 'my_list', right. Some list 232 00:12:25,300 --> 00:12:28,100 is there. Simply do 'dir' of your list. 233 00:12:28,100 --> 00:12:30,300 [no audio] 234 00:12:30,300 --> 00:12:34,500 See. Guys, these are for your documentation 235 00:12:34,500 --> 00:12:37,400 purpose because the list is actually an object for your 236 00:12:37,400 --> 00:12:39,400 some of the Python classes, okay. 237 00:12:39,400 --> 00:12:42,600 That's why these are the documentation related things. 238 00:12:43,200 --> 00:12:45,400 So you have to know only without underscore whatever you 239 00:12:45,400 --> 00:12:47,000 have, that are you our operations. 240 00:12:47,000 --> 00:12:50,700 [no audio] 241 00:12:50,700 --> 00:12:55,500 Right. Now, see what are the operations there - append, clear, copy, 242 00:12:55,500 --> 00:12:59,100 count, extend, index, insert, pop, remove, reverse, and sort. 243 00:13:00,500 --> 00:13:06,200 First let me go with append, insert, extend. 244 00:13:07,300 --> 00:13:09,400 Yeah, I will go with first index because that is also one 245 00:13:09,400 --> 00:13:13,600 of the important one. See let me, index is nothing but getting 246 00:13:14,200 --> 00:13:19,600 an index value of a particular value. 'index()', let's say 5 247 00:13:19,600 --> 00:13:23,300 index. What is the index of 5? 1, because 5 is occurring at 248 00:13:23,300 --> 00:13:25,600 [no audio] 249 00:13:25,600 --> 00:13:28,200 first position. Sorry, second value means index is 1, right. 250 00:13:29,600 --> 00:13:31,300 Okay. Now, 251 00:13:31,300 --> 00:13:33,400 [no audio] 252 00:13:33,400 --> 00:13:37,900 then that is one thing. You may get doubt, in case if you have 253 00:13:37,900 --> 00:13:41,500 multiple fives in your list, right. Suppose 254 00:13:41,500 --> 00:13:42,700 I have somewhere here 5. 255 00:13:42,700 --> 00:13:47,200 [no audio] 256 00:13:47,200 --> 00:13:49,900 Now I am running. You're getting index 1 means this index 257 00:13:49,900 --> 00:13:51,400 value. Then what about this 5? 258 00:13:52,600 --> 00:13:55,900 So in case if you are getting 1 no, just try to search 259 00:13:57,100 --> 00:14:01,900 after index 1. That means from index 2 just try to search 260 00:14:01,900 --> 00:14:04,000 and see if there are, if there is any one more 5. 261 00:14:04,000 --> 00:14:07,800 Yes, it is there at 6th index, means seventh value. 262 00:14:07,800 --> 00:14:10,200 [no audio] 263 00:14:10,200 --> 00:14:12,200 Okay, fine. 264 00:14:13,000 --> 00:14:15,700 So you don't worry about if you have multiple values how 265 00:14:15,700 --> 00:14:18,700 to work with that, we'll have a separate section for that. 266 00:14:18,700 --> 00:14:22,300 There we'll discuss it. For time being if values are unique 267 00:14:22,300 --> 00:14:25,100 how to work with them, okay. 268 00:14:26,500 --> 00:14:30,300 Fine. Now, actually the good thing is 'regex'. We have regular 269 00:14:30,300 --> 00:14:32,600 expressions. There we can do lot of things. 270 00:14:33,300 --> 00:14:36,700 Meanwhile, we just try to no minimum things from your list. 271 00:14:38,600 --> 00:14:43,400 Okay, index done. Then let me take count also. See count is 272 00:14:43,400 --> 00:14:45,400 nothing but, let me print 273 00:14:45,400 --> 00:14:47,800 [no audio] 274 00:14:47,800 --> 00:14:49,000 your list '.' 275 00:14:49,000 --> 00:14:51,200 [no audio] 276 00:14:51,200 --> 00:14:55,000 'count()', any number. Let's say I want to count number 10, 277 00:14:55,000 --> 00:14:56,900 how many times it is there in my given list? 278 00:14:58,400 --> 00:15:01,500 0 times. I don't have any 10 in my list, right? 279 00:15:01,600 --> 00:15:04,700 That's why are getting output as 0. Now, 280 00:15:04,700 --> 00:15:05,600 let's say suppose 281 00:15:05,600 --> 00:15:09,200 I want to count a number which is having suppose 282 00:15:09,200 --> 00:15:11,200 [no audio] 283 00:15:11,200 --> 00:15:14,800 Three times 5 is there, no. Now I am going to count number 284 00:15:14,800 --> 00:15:17,300 5, how many times it is there in my given list? 285 00:15:18,600 --> 00:15:21,000 Three times. That's it. 286 00:15:22,000 --> 00:15:23,000 Okay. 287 00:15:23,800 --> 00:15:26,600 Fine. Now that is about count. 288 00:15:26,600 --> 00:15:29,000 [no audio] 289 00:15:29,000 --> 00:15:31,000 Any next related operation? 290 00:15:31,000 --> 00:15:34,600 [no audio] 291 00:15:34,600 --> 00:15:38,900 Yeah, 'clear'. Very simple one. Clear is nothing but, see guys before 292 00:15:38,900 --> 00:15:40,600 running my 'clear' operation 293 00:15:40,600 --> 00:15:41,900 I am printing 'my_list'. 294 00:15:41,900 --> 00:15:44,300 [no audio] 295 00:15:44,300 --> 00:15:52,200 Then 'my_list.clear'. Then 'print(my_list)'. See the output. 296 00:15:53,400 --> 00:15:55,000 You are simply clearing your list. 297 00:15:55,200 --> 00:16:02,500 So that is the usage of your 'clear'. Guys, if you observe sometimes 298 00:16:02,500 --> 00:16:04,500 I am doing operation in print itself, 299 00:16:04,500 --> 00:16:06,800 sometimes I am doing operation separately. 300 00:16:06,900 --> 00:16:13,100 The reason is, here you are trying to get the, fetch the information. 301 00:16:13,100 --> 00:16:15,100 This operation is like counting, no. You're counting, you are 302 00:16:15,100 --> 00:16:16,100 not modifying. 303 00:16:16,700 --> 00:16:19,600 So modifying operations don't do with print. 304 00:16:19,600 --> 00:16:21,800 [no audio] 305 00:16:21,800 --> 00:16:24,600 Okay. Directly, whatever the operation you are performing 306 00:16:24,600 --> 00:16:28,800 that modification will modify in the original data itself. 307 00:16:28,800 --> 00:16:32,800 Because lists are mutable, whatever the operation you are performing 308 00:16:33,100 --> 00:16:36,600 that operation will modify the original data itself. 309 00:16:36,600 --> 00:16:38,500 [no audio] 310 00:16:38,500 --> 00:16:41,300 Right. So that's why I'm not using this in 'print' statement. 311 00:16:41,300 --> 00:16:44,800 When you will use 'print'? If you want to see the existing information, 312 00:16:44,800 --> 00:16:48,100 that type of operations you have to work with 'print', or you 313 00:16:48,100 --> 00:16:51,000 can also store that result into some variable and that variable 314 00:16:51,000 --> 00:16:54,300 you can print. Let's say I want to count how many times 5 315 00:16:54,300 --> 00:16:57,800 is there, so directly I am printing the count. Instead of that 316 00:16:57,800 --> 00:16:58,600 what I will do, 317 00:16:59,800 --> 00:17:06,200 'cont_five', any variable. Then in this way. And I can print this variable. 318 00:17:06,598 --> 00:17:09,400 So why should we take extra variable and why should we print 319 00:17:09,400 --> 00:17:14,000 that? That's why I am directly printing. But don't print this data. 320 00:17:15,098 --> 00:17:16,700 Right, this is operation. 321 00:17:17,000 --> 00:17:18,300 You're modifying something. 322 00:17:18,500 --> 00:17:22,700 So if any operation is related to modification, that directly 323 00:17:22,700 --> 00:17:24,900 perform in this way. Don't use print for that. 324 00:17:25,800 --> 00:17:29,300 Anyway, after some practice you will come to know that but 325 00:17:29,300 --> 00:17:30,800 meanwhile just remember that. 326 00:17:32,300 --> 00:17:36,200 So 'clear' is done. Then let me go with 'copy', right? 327 00:17:36,400 --> 00:17:39,300 See guys, if you want to assign one variable value to other, 328 00:17:39,300 --> 00:17:44,800 let's say 'x=4', and I want to assign 'x' value to 329 00:17:44,800 --> 00:17:50,000 'y'. I can assign in this way, right. Same way, suppose 'my_new_list' 330 00:17:50,000 --> 00:17:53,099 I am taking equals to 'my_list'. 331 00:17:53,099 --> 00:17:56,700 [no audio] 332 00:17:56,700 --> 00:17:59,400 Okay, or 'my_one_more_list' 333 00:17:59,400 --> 00:18:03,600 I am taking equals to 'my_list.copy'. 334 00:18:04,900 --> 00:18:06,500 Both are same. Nothing there. 335 00:18:06,500 --> 00:18:09,500 You're assigning this values to this one. This 336 00:18:09,500 --> 00:18:10,500 values to this one. 337 00:18:12,200 --> 00:18:15,300 Both are same, but there is a small difference that is, whenever 338 00:18:15,300 --> 00:18:18,900 if you directly assign in this way, you are not going to 339 00:18:18,900 --> 00:18:23,100 create a new memory location instead of that, instead of that, 340 00:18:23,100 --> 00:18:24,400 be clear, suppose 341 00:18:24,400 --> 00:18:25,400 assume that your list 342 00:18:25,400 --> 00:18:27,500 is there somewhere in RAM memory, 343 00:18:28,200 --> 00:18:31,400 same address is pointing to this variable also. Actually, 344 00:18:31,400 --> 00:18:33,100 this is for your original variable. 345 00:18:33,700 --> 00:18:35,900 Same address is pointing to this variable. 346 00:18:37,000 --> 00:18:41,000 But if you do 'copy', other memory location will be created. 347 00:18:41,100 --> 00:18:43,700 That address memory location will be point out to this variable. 348 00:18:43,700 --> 00:18:45,000 That is the use of 'copy'. 349 00:18:45,000 --> 00:18:48,200 [no audio] 350 00:18:48,200 --> 00:18:49,800 Right. Let me prove that. 351 00:18:51,000 --> 00:18:57,700 'print(id())', 'id' means, address location, right, 'my_list', and then 352 00:18:57,700 --> 00:19:04,600 let me take 'id(my_new_list)'. Then I am printing the 353 00:19:04,600 --> 00:19:16,800 last one separately, 'print(id(my_one_list))'. Just see the 354 00:19:16,800 --> 00:19:21,100 output. See for these two you're getting same 'id' locations, 355 00:19:21,200 --> 00:19:24,700 but for last one different. So that is the use of 'copy' operation. 356 00:19:26,100 --> 00:19:27,600 Right. Fine. 357 00:19:27,700 --> 00:19:31,000 So this is about 'copy', or assigning one list to other list. 358 00:19:31,500 --> 00:19:35,500 So there are two ways - one is assigning same memory location 359 00:19:35,500 --> 00:19:39,300 address, referring to same memory location, or create a new 360 00:19:39,300 --> 00:19:41,100 memory location and store the result, 361 00:19:41,100 --> 00:19:43,400 then that result we are assigning to different variable. 362 00:19:44,700 --> 00:19:47,000 That's fine. Now, let me go with, 363 00:19:47,000 --> 00:19:50,700 [no audio] 364 00:19:50,700 --> 00:19:56,500 I will go with now 'append'. 'append' is nothing but, see as of 365 00:19:56,500 --> 00:19:57,500 now what is your data? 366 00:19:57,900 --> 00:19:59,500 See that. 'print(my_list)'. 367 00:20:02,000 --> 00:20:04,100 [3, 5, 2, 7, 3, 8, 9], right? 368 00:20:05,100 --> 00:20:10,500 Now, I want to add some new data at the end of my list. 369 00:20:10,800 --> 00:20:13,400 That is nothing but generally, that operation is called generally 370 00:20:13,400 --> 00:20:16,800 appending. So appending is nothing but for existing information 371 00:20:16,800 --> 00:20:19,100 at the end you are adding something that is the meaning of 372 00:20:19,100 --> 00:20:21,900 appending. Same thing is applicable with your list 373 00:20:21,900 --> 00:20:27,000 also. Let's say 'my_list.append'. So guys for this operation also 374 00:20:27,000 --> 00:20:29,500 I'm not using 'print' statement because this is going to 375 00:20:29,500 --> 00:20:32,600 modify your data. Whenever if you are modifying your list 376 00:20:33,200 --> 00:20:34,200 that operation 377 00:20:34,500 --> 00:20:35,800 don't do with print. 378 00:20:36,900 --> 00:20:40,700 'my_list.append', I want to append some number 56. 379 00:20:41,100 --> 00:20:44,000 So after appending just observe the result. 380 00:20:44,000 --> 00:20:46,700 [no audio] 381 00:20:46,700 --> 00:20:51,500 56 added at the end, but I want to add this 56 somewhere 382 00:20:51,600 --> 00:20:52,900 between 3 and 5, 383 00:20:54,300 --> 00:20:58,800 or between 2 and 7, anywhere. In case if I insert between 384 00:20:58,800 --> 00:21:03,300 3 and 5, after inserting my number, whatever I am going to 385 00:21:03,300 --> 00:21:08,300 insert, that inserted data index will be 1 because 3 is 0, 386 00:21:08,300 --> 00:21:11,300 5 is 1 as of now. But if I insert between this you are 387 00:21:11,300 --> 00:21:16,000 getting, right. So see that, 'my_list. 388 00:21:17,200 --> 00:21:18,200 insert', 389 00:21:18,200 --> 00:21:22,200 [no audio] 390 00:21:22,200 --> 00:21:24,200 let's say index 391 00:21:25,900 --> 00:21:30,700 1, value 45. Then after inserting see your list. 392 00:21:30,700 --> 00:21:35,600 [no audio] 393 00:21:35,600 --> 00:21:37,800 See, between 3 and 5 you inserted 394 00:21:37,800 --> 00:21:40,300 your data based on index position. 395 00:21:41,000 --> 00:21:42,800 'append' is going to add at the end, 396 00:21:43,000 --> 00:21:46,600 but 'insert' is going to add based on index position where 397 00:21:46,600 --> 00:21:47,600 you want to insert. 398 00:21:48,200 --> 00:21:52,700 So 1, index 1, I should have a value called 45. Then see that, 399 00:21:52,700 --> 00:21:54,900 3, 45, 5. 400 00:21:54,900 --> 00:22:00,200 So 3 is 0, 45 is 1, right. So 'append', 'insert' are used to add 401 00:22:00,200 --> 00:22:03,800 your data to your list. 'append' is going to add your data at 402 00:22:03,800 --> 00:22:05,300 the end, 'insert' is going to add 403 00:22:05,500 --> 00:22:09,100 data to your existing list based on your required index position. 404 00:22:10,900 --> 00:22:12,200 Right. Fine. 405 00:22:12,400 --> 00:22:15,400 Now you have one more thing called 'extend' operation. See that 406 00:22:15,400 --> 00:22:18,000 somewhere you have 'extend'. 'extend', 407 00:22:18,000 --> 00:22:19,900 [no audio] 408 00:22:19,900 --> 00:22:22,200 right. So we have seen 'insert', 409 00:22:22,800 --> 00:22:24,000 Let me go with 'extend'. 410 00:22:24,000 --> 00:22:26,600 [no audio] 411 00:22:26,600 --> 00:22:27,300 So suppose 412 00:22:27,300 --> 00:22:29,400 I have one new list called 413 00:22:29,400 --> 00:22:32,000 [no audio] 414 00:22:32,000 --> 00:22:38,200 5 and 6. If I simply do 'my_list.append 415 00:22:39,800 --> 00:22:44,800 (my_new_list)', and after this operation, just observe your output, 416 00:22:44,800 --> 00:22:46,200 how you are getting your list. 417 00:22:47,700 --> 00:22:51,100 'append' means at the end you are adding your 5, 6 data. 418 00:22:52,100 --> 00:22:56,800 As the list of, see last value is also one list, you're 419 00:22:56,800 --> 00:22:57,700 getting square brackets, 420 00:22:57,700 --> 00:23:02,700 no, but instead of 'append', instead of 'append' if I take 'extend', 421 00:23:02,700 --> 00:23:04,700 [no audio] 422 00:23:04,700 --> 00:23:07,200 now see the result. You don't have the square brackets. Directly 423 00:23:07,200 --> 00:23:10,400 it is normal data. You are adding your list as a normal 424 00:23:10,400 --> 00:23:13,800 data into your existing list. That's it. 425 00:23:13,800 --> 00:23:16,800 [no audio] 426 00:23:16,800 --> 00:23:20,200 So that is all about your 'extend'. 427 00:23:20,200 --> 00:23:25,200 [no audio] 428 00:23:25,200 --> 00:23:26,200 Fine. 429 00:23:27,000 --> 00:23:31,500 So we're done with 'append', 'clear', 'copy', 'count', 'extend', 'index' also 430 00:23:31,500 --> 00:23:36,700 done, 'insert' done, now 'pop' and 'remove'. 'remove' is going to remove 431 00:23:36,700 --> 00:23:40,100 your value directly. 'pop' is going to remove based on index 432 00:23:40,100 --> 00:23:45,200 position. Let's say I am doing first thing your list, 433 00:23:45,200 --> 00:23:46,500 so as of now what is your list? 434 00:23:46,500 --> 00:23:47,200 Let me check it. 435 00:23:47,200 --> 00:23:49,700 [no audio] 436 00:23:49,700 --> 00:23:52,100 So this is your list, right? 437 00:23:53,400 --> 00:23:57,100 So I am doing some operation called 'my_list.remove', 438 00:23:57,800 --> 00:23:59,700 let's say a value called 10. 439 00:23:59,700 --> 00:24:01,700 [no audio] 440 00:24:01,700 --> 00:24:04,200 Right. After this I am trying to print. Actually you don't 441 00:24:04,200 --> 00:24:05,700 have a number 10 in your list. 442 00:24:06,000 --> 00:24:08,000 But if I do that, see that, what you are getting. 443 00:24:09,300 --> 00:24:12,500 x is not in the list. That means whatever the value you are 444 00:24:12,500 --> 00:24:15,000 removing that is not in the list, right? 445 00:24:15,100 --> 00:24:17,700 So in your real time whenever if you are doing this operation 446 00:24:17,700 --> 00:24:19,300 before that you will take some condition, 447 00:24:19,300 --> 00:24:21,000 'if' condition, then we will remove it. 448 00:24:21,100 --> 00:24:23,300 If it is there then only we will remove. If it is not there 449 00:24:23,300 --> 00:24:24,200 we don't remove it. 450 00:24:25,300 --> 00:24:29,500 In case whatever the value you are having that value I want to remove, 451 00:24:30,600 --> 00:24:33,200 right. So what are the values we are having? 3, 5, 2, 7. 452 00:24:33,200 --> 00:24:34,400 Let me take 8. 453 00:24:34,400 --> 00:24:36,400 [no audio] 454 00:24:36,400 --> 00:24:40,100 Now see the output. After remove operation you are removing number 8. 455 00:24:41,700 --> 00:24:45,200 Right. Now, let me comment 'remove'. 456 00:24:45,200 --> 00:24:49,000 [no audio] 457 00:24:49,000 --> 00:24:52,200 Now what I am doing is, you have 'pop' operation. 458 00:24:54,100 --> 00:24:57,300 First, let me do this, 'my_list.pop'. 459 00:24:57,800 --> 00:24:59,800 I am not giving any index position. 460 00:24:59,800 --> 00:25:02,000 First see the output what it is doing. 461 00:25:02,000 --> 00:25:03,900 [no audio] 462 00:25:03,900 --> 00:25:07,400 So before 'pop' this is the data, after 'pop' this is the data. 463 00:25:09,000 --> 00:25:13,000 Right. So by default 'pop' will remove the last data. 464 00:25:14,100 --> 00:25:17,400 If you give index position, let's say I am giving index 2, index 465 00:25:17,400 --> 00:25:22,600 2, or let's say index 0, now see the output. If you provide 466 00:25:22,600 --> 00:25:24,900 index position it will remove that data. 467 00:25:25,200 --> 00:25:28,000 If you don't provide, by default it will remove the last 468 00:25:28,000 --> 00:25:33,700 data, last index value, right. And one important point 469 00:25:33,700 --> 00:25:35,600 is there with your 'pop' operation. 470 00:25:35,600 --> 00:25:38,900 [no audio] 471 00:25:38,900 --> 00:25:40,100 Let me show you that. 472 00:25:41,300 --> 00:25:45,400 So as of now, what is your list? This is your list, right. 'print'. 473 00:25:46,800 --> 00:25:50,800 Actually, your 'pop' is modifying your data, right? 474 00:25:50,800 --> 00:25:54,300 That's why actually you should not use your direct operation, 475 00:25:54,300 --> 00:25:58,300 'my_list.pop' into print. But there is a special property 476 00:25:58,300 --> 00:26:03,400 with your 'pop', that is, your 'pop' will remove your data at the 477 00:26:03,400 --> 00:26:05,700 same time it also gives what is the data 478 00:26:05,700 --> 00:26:09,900 it is going to remove. That's why I can use it in my 'print' statement. 479 00:26:09,900 --> 00:26:12,700 [no audio] 480 00:26:12,700 --> 00:26:16,500 See the output. It is removing 9, that is it is 481 00:26:16,500 --> 00:26:18,200 giving. At the same time 482 00:26:18,200 --> 00:26:20,300 that data is removed from your list. 483 00:26:20,400 --> 00:26:21,900 That's why, see the output. 484 00:26:23,100 --> 00:26:27,200 So only 'pop' operation will give 485 00:26:27,200 --> 00:26:31,000 the data what it is removing, at the same time 486 00:26:31,000 --> 00:26:33,100 it will remove in your original data. 487 00:26:34,600 --> 00:26:37,400 Right. So that is the use of 'pop'. 488 00:26:38,500 --> 00:26:41,500 Now let me comment this. Now we have 489 00:26:41,500 --> 00:26:44,300 [no audio] 490 00:26:44,300 --> 00:26:48,100 'reverse' and 'sort'. Let me do with 'sort' first. 491 00:26:48,100 --> 00:26:50,200 [no audio] 492 00:26:50,200 --> 00:26:53,600 Otherwise, as of now what is your data, guys? 493 00:26:53,700 --> 00:26:54,900 See that output once. 494 00:26:54,900 --> 00:26:55,900 This is your data. 495 00:26:55,900 --> 00:26:57,800 [no audio] 496 00:26:57,800 --> 00:27:00,600 Okay. Now I am doing something called 497 00:27:00,600 --> 00:27:03,200 [no audio] 498 00:27:03,200 --> 00:27:04,700 'my_list., 499 00:27:04,800 --> 00:27:06,000 let me do 'reverse' first, 500 00:27:06,000 --> 00:27:08,500 [no audio] 501 00:27:08,500 --> 00:27:11,300 and after 'reverse' see what is your list is there? 502 00:27:11,300 --> 00:27:13,600 [no audio] 503 00:27:13,600 --> 00:27:16,900 See before 'reverse' operation, and after 'reverse' operation. 504 00:27:17,100 --> 00:27:19,500 So it is like, you know mirror image of your data. 505 00:27:20,700 --> 00:27:24,400 Right. Now, let me comment your 'reverse' operation, and I am 506 00:27:24,400 --> 00:27:27,600 going to do 'my_list.sort' operation. 507 00:27:28,400 --> 00:27:32,700 So 'sort' is nothing but, it is going to arrange your data 508 00:27:32,700 --> 00:27:35,100 in ascending order. See that. 509 00:27:35,100 --> 00:27:37,700 [no audio] 510 00:27:37,700 --> 00:27:40,500 Now if you want to get data in 511 00:27:40,500 --> 00:27:45,400 descending order, first perform 'sort', and then do your 'reverse' operation. 512 00:27:45,400 --> 00:27:47,800 [no audio] 513 00:27:47,800 --> 00:27:51,900 Now see the output, descending order. Or else 514 00:27:51,900 --> 00:27:56,300 you can also use shortcut as 'my_list.sort', here 515 00:27:56,300 --> 00:27:58,200 you can write 'reverse=True'. 516 00:27:59,100 --> 00:28:01,800 So instead of performing 'reverse' separately you can also 517 00:28:01,800 --> 00:28:03,700 do in this way. Now see the result. 518 00:28:03,800 --> 00:28:06,600 Yes, you are getting in the reverse order, right. 519 00:28:06,900 --> 00:28:10,200 So guys, these all are the operations on your list, 520 00:28:10,700 --> 00:28:13,700 okay. So in next video, we'll discuss about tuple. 521 00:28:13,700 --> 00:28:15,700 [no audio] 522 00:28:15,700 --> 00:28:17,500 Right. Okay guys, 523 00:28:17,500 --> 00:28:19,000 thank you for watching this video. 524 00:28:19,000 --> 00:28:27,800 [no audio]