1 00:00:00,219 --> 00:00:03,710 All right. So let's begin by talking about lists. 2 00:00:03,720 --> 00:00:06,429 Now, lists aren't anything new to us. 3 00:00:06,440 --> 00:00:08,979 We've actually worked with quite a few lists already. 4 00:00:09,189 --> 00:00:12,670 We've had lists of names, lists of cars and so on. 5 00:00:13,050 --> 00:00:18,110 But the one thing about lists is that they are what we call mutable, 6 00:00:18,500 --> 00:00:23,510 meaning that the items or elements that you have in a list, 7 00:00:23,559 --> 00:00:25,909 we can actually modify them, right? 8 00:00:26,110 --> 00:00:28,149 So we can add to the list, 9 00:00:28,379 --> 00:00:30,760 we can remove from the list and we can modify 10 00:00:30,770 --> 00:00:34,450 whatever elements that already exist within that particular list. 11 00:00:34,459 --> 00:00:35,930 Now, over here, 12 00:00:36,330 --> 00:00:39,139 I do have a list of compromised passwords. 13 00:00:39,150 --> 00:00:45,619 So you know the usual password, 12345, Qwlty and so on. 14 00:00:45,880 --> 00:00:47,740 Now, I want to show you a 15 00:00:47,930 --> 00:00:50,130 few things that we can do in here, right? 16 00:00:50,509 --> 00:00:52,200 I can say print, 17 00:00:52,740 --> 00:00:54,799 ok. And now in brackets, 18 00:00:55,889 --> 00:00:59,869 I can call the list, compromised passwords. 19 00:01:00,400 --> 00:01:03,909 And now I can provide the index number 20 00:01:04,598 --> 00:01:09,499 of the item that I want to list. In this case. Right now, it is 21 00:01:09,708 --> 00:01:11,499 index number zero. 22 00:01:11,738 --> 00:01:15,179 If I run my program, you can see that's going to be password. 23 00:01:15,348 --> 00:01:19,289 So the first thing I want you to understand is that the items in a list, 24 00:01:19,299 --> 00:01:22,899 they all have index numbers starting from zero. 25 00:01:23,278 --> 00:01:27,738 So if I was to print index number two, what do you think the answer would be? 26 00:01:28,620 --> 00:01:32,589 Yep, it's gonna be QWE rt Y 27 00:01:32,809 --> 00:01:33,480 OK. 28 00:01:33,720 --> 00:01:35,660 That's the first thing I want you to understand. 29 00:01:35,959 --> 00:01:43,599 Next is the fact that we can perform various types of functions on our list. 30 00:01:43,809 --> 00:01:45,000 For example, 31 00:01:45,650 --> 00:01:49,000 I can say, let me call the list again 32 00:01:49,430 --> 00:01:50,120 And now 33 00:01:50,279 --> 00:01:53,480 I can add this function here called append 34 00:01:54,919 --> 00:01:56,199 a pen right here 35 00:01:56,419 --> 00:01:59,419 in technical terms is what we refer to as a method. 36 00:01:59,529 --> 00:02:01,699 Methods are also functions, 37 00:02:01,879 --> 00:02:04,980 but they are very special kinds of functions. We'll talk about methods a bit later. 38 00:02:04,989 --> 00:02:08,399 But for now, just understand that we do have very special functions, 39 00:02:08,410 --> 00:02:09,699 functions that are called methods 40 00:02:09,850 --> 00:02:14,199 that you can apply directly onto lists and they will do something. 41 00:02:14,550 --> 00:02:15,600 So right now, 42 00:02:15,869 --> 00:02:23,600 what a pen would do is that it will add whatever new item you want into our list. So 43 00:02:23,919 --> 00:02:26,580 as an example, I can open up my brackets 44 00:02:27,300 --> 00:02:30,080 and let's say we add a swordfish, 45 00:02:30,259 --> 00:02:31,080 OK? This is 46 00:02:31,190 --> 00:02:32,440 a very, very popular 47 00:02:32,679 --> 00:02:33,119 pages 48 00:02:33,380 --> 00:02:34,360 by a lot of people. 49 00:02:34,490 --> 00:02:35,169 OK? 50 00:02:35,410 --> 00:02:38,059 So I've appended salt fish to the list. 51 00:02:38,070 --> 00:02:42,110 So if I go back right now and I print my compromised passwords, 52 00:02:42,399 --> 00:02:49,240 you can see salt fish has been added to the list. So this is the very first 53 00:02:49,649 --> 00:02:54,270 a method of function. I want you to understand that you can use with your lists. 54 00:02:54,559 --> 00:02:58,149 The next one is going to be what we call the extend 55 00:02:58,360 --> 00:02:59,309 function. 56 00:02:59,520 --> 00:03:00,320 See a 57 00:03:00,529 --> 00:03:02,460 pen with a pen, you can add, 58 00:03:02,779 --> 00:03:07,250 you know, individual items, elements and so on. With extend, 59 00:03:07,449 --> 00:03:13,080 you can actually add all elements from another list. 60 00:03:13,089 --> 00:03:18,270 So as an example, I have my first list right there, uh compromised passwords. 61 00:03:18,429 --> 00:03:22,080 And let's say we've created another list 62 00:03:22,589 --> 00:03:24,509 of compromised passwords. 63 00:03:25,449 --> 00:03:26,100 Ok. 64 00:03:26,399 --> 00:03:28,380 Equals and now let me open up 65 00:03:28,759 --> 00:03:30,270 the brackets in here 66 00:03:31,130 --> 00:03:35,220 and let's add some fresh batch of passwords. 67 00:03:35,509 --> 00:03:40,500 Let's see, we have what are the very common passwords people often use? 68 00:03:40,509 --> 00:03:45,110 Ok, let's say 123 AB C. 69 00:03:45,460 --> 00:03:46,449 How about that? 70 00:03:46,880 --> 00:03:48,350 And let me add 71 00:03:48,479 --> 00:03:49,419 one more 72 00:03:50,630 --> 00:03:55,089 and let's call that one dog cat Bone, 73 00:03:56,830 --> 00:04:00,320 you know, just something. All right. Ok. So we now have two different lists, right? 74 00:04:00,610 --> 00:04:02,369 One for the compromised passwords and then 75 00:04:02,380 --> 00:04:05,440 another for the new compromised passwords. 76 00:04:05,610 --> 00:04:08,949 So check this out. Ok, I can come here right now 77 00:04:09,610 --> 00:04:10,330 and say 78 00:04:11,220 --> 00:04:14,399 compromise passwords and now extend 79 00:04:15,320 --> 00:04:17,100 and now in brackets, 80 00:04:17,350 --> 00:04:18,890 I can say new 81 00:04:19,209 --> 00:04:19,730 on this 82 00:04:20,000 --> 00:04:21,820 compromised password. So basically 83 00:04:22,058 --> 00:04:26,789 I am attaching the new passwords into the old passwords list. 84 00:04:27,028 --> 00:04:30,148 And now if I run my program, 85 00:04:30,289 --> 00:04:33,739 now you can see that 123 AB C and Dog 86 00:04:33,748 --> 00:04:39,359 Cat Bone have been added to my compromised passwords list. 87 00:04:39,368 --> 00:04:39,739 Now, 88 00:04:39,748 --> 00:04:44,319 another method I want you to be aware of is going to be quite the opposite of append, 89 00:04:44,329 --> 00:04:46,678 which is going to be remove. 90 00:04:46,688 --> 00:04:48,278 So let me first of all 91 00:04:48,519 --> 00:04:49,658 cut out 92 00:04:50,899 --> 00:04:52,910 our first or second list rather 93 00:04:54,089 --> 00:04:58,500 and I am going to modify this line right here and then say 94 00:04:58,619 --> 00:05:00,179 remove. 95 00:05:00,760 --> 00:05:02,140 And now in brackets, 96 00:05:02,380 --> 00:05:05,019 just as an example, I can provide 97 00:05:05,839 --> 00:05:08,779 what I want to remove, which is 12345. 98 00:05:09,239 --> 00:05:14,019 So let's say I wanted to remove this particular element. Very, very easy. 99 00:05:14,029 --> 00:05:15,989 I'll just say that remove, run. 100 00:05:16,089 --> 00:05:19,170 And now you can see that 12345 is no longer 101 00:05:19,450 --> 00:05:20,059 in the 102 00:05:20,429 --> 00:05:23,700 coin passwords list. So very, very straightforward. 103 00:05:23,790 --> 00:05:26,670 Another one we can do is to simply clear, 104 00:05:26,850 --> 00:05:31,779 we can clear the entire list as an example. So if I was to come over here right now, 105 00:05:32,089 --> 00:05:33,980 change, remove to clear. 106 00:05:34,459 --> 00:05:37,579 All right, I don't need to have anything inside the brackets. 107 00:05:37,839 --> 00:05:39,959 So just clear and if I run, 108 00:05:40,170 --> 00:05:40,959 there you go, 109 00:05:41,119 --> 00:05:45,440 it is going to be empty. There is nothing inside of the list any more. 110 00:05:45,450 --> 00:05:49,109 So there's quite a few other methods that you can work with. 111 00:05:49,119 --> 00:05:50,880 I think it's about 11 of them. 112 00:05:51,059 --> 00:05:53,470 But let me give you two more. 113 00:05:53,820 --> 00:05:57,149 Another more we can use is going to be a reverse. 114 00:05:57,510 --> 00:06:01,140 All right. So basically what this will simply do is that it will reverse 115 00:06:01,470 --> 00:06:06,140 the items in the list. The order is going to reverse the order. So if I run this, 116 00:06:06,359 --> 00:06:07,859 there you go, it starts from 117 00:06:08,010 --> 00:06:11,420 uh let me in and goes backwards all the way to password 118 00:06:11,619 --> 00:06:13,579 and then one more 119 00:06:13,970 --> 00:06:17,540 that I want to show you that can be very useful would be the copy 120 00:06:17,660 --> 00:06:18,980 method. So 121 00:06:19,320 --> 00:06:20,940 as an example over here, 122 00:06:21,320 --> 00:06:25,679 let me just come right here and I'll create a backup. Ok? So 123 00:06:25,820 --> 00:06:29,540 backup and let's say underscore accounts, 124 00:06:30,579 --> 00:06:31,239 ok? 125 00:06:31,769 --> 00:06:34,179 I can assign the backup to my variable backup 126 00:06:34,190 --> 00:06:38,079 account and I can now say equals and now compromised 127 00:06:38,809 --> 00:06:40,279 uh passwords 128 00:06:40,429 --> 00:06:41,829 and now dot 129 00:06:42,010 --> 00:06:43,010 copy 130 00:06:43,250 --> 00:06:44,660 and now in brackets. 131 00:06:45,950 --> 00:06:50,739 All right. So basically what I'm doing right now is I would like to make a backup 132 00:06:51,029 --> 00:06:54,670 of this list, this compromised password list and then assign that 133 00:06:54,880 --> 00:06:56,950 to the variable backup accounts. 134 00:06:57,160 --> 00:06:59,329 So now if I was to print 135 00:07:00,019 --> 00:07:02,519 the backup accounts 136 00:07:03,420 --> 00:07:04,359 and I run, 137 00:07:04,769 --> 00:07:07,690 you will see right now that we have the exact same 138 00:07:07,940 --> 00:07:10,359 list, the exact same item. So 139 00:07:10,589 --> 00:07:14,510 this is what you would use to create backups or copy 140 00:07:14,679 --> 00:07:17,220 the items in a particular list. 141 00:07:17,239 --> 00:07:22,440 So, like I said, you do have a few other ones like salt pop and so on. 142 00:07:22,670 --> 00:07:26,170 We're going to talk about methods a bit later in the course. 143 00:07:26,179 --> 00:07:28,739 But for now that's the introduction to lists and the 144 00:07:28,750 --> 00:07:31,690 methods that you can use to work with them. 145 00:07:31,700 --> 00:07:34,049 Thank you for watching. I will see you in the next class.