1 00:00:00,410 --> 00:00:07,790 Oh yes and welcome back to another class of our course about the complete introduction to fight on programming. 2 00:00:09,330 --> 00:00:16,170 So today we are going to still talk about lists but instead of just talking about the basics we are 3 00:00:16,170 --> 00:00:18,080 going to talk about list functions. 4 00:00:18,080 --> 00:00:21,920 So as we said the beginning of this squares there are many types of functions that exist. 5 00:00:21,990 --> 00:00:26,670 You can apply function to strings you can apply functions to numbers you can apply functions to well 6 00:00:26,790 --> 00:00:32,790 you have many types of functions on Python but you can also apply functions on lists. 7 00:00:32,790 --> 00:00:34,990 So what exactly are list functions. 8 00:00:34,980 --> 00:00:42,160 So technically it's just simple manipulations that you can do on lists by yeah. 9 00:00:42,210 --> 00:00:45,530 Well writing down functions so functions can for example. 10 00:00:45,720 --> 00:00:52,950 I don't know help you add something in your list can help you let's say copy and past your list can 11 00:00:52,950 --> 00:00:57,090 help you count the number of elements that you have in your list. 12 00:00:57,090 --> 00:01:01,530 So what I personally done you have you have hundreds of different functions but what I personally have 13 00:01:01,530 --> 00:01:08,970 done I simply look for the most popular functions that exists about the lists and I selected five of 14 00:01:09,000 --> 00:01:12,260 the most used functions for lists. 15 00:01:12,270 --> 00:01:17,930 Well the most use that list functions that are used in Python. 16 00:01:18,250 --> 00:01:23,650 So basically what we will do today is I will show you I'll give you an introduction to functions to 17 00:01:23,650 --> 00:01:24,770 list functions. 18 00:01:24,760 --> 00:01:32,140 And if you guys are interested you can after that go on the internet and just find out many other list 19 00:01:32,140 --> 00:01:34,040 functions and try them out by yourself. 20 00:01:34,570 --> 00:01:36,500 So we'll see it's not very hard to understand. 21 00:01:36,520 --> 00:01:36,790 All right. 22 00:01:36,970 --> 00:01:42,670 So let's start the first thing that we are going to talk about will be the function answer. 23 00:01:42,760 --> 00:01:48,910 So let's say for example the first thing they'll ask you is write down a book well two lists so a list 24 00:01:48,970 --> 00:01:53,890 of numbers and a list of a list of strings. 25 00:01:54,100 --> 00:01:56,890 So we'll start by the first function. 26 00:01:56,920 --> 00:02:00,190 This function will help us insert something in a list. 27 00:02:00,190 --> 00:02:06,610 So let's say for example in this list of words where this is this list is called food and I want to 28 00:02:06,610 --> 00:02:09,310 insert another type of food right here. 29 00:02:09,310 --> 00:02:11,250 So what exactly I will do. 30 00:02:11,740 --> 00:02:13,080 So let's say for example I want. 31 00:02:13,100 --> 00:02:15,120 Well I'll start by printing this list. 32 00:02:15,220 --> 00:02:18,880 I want to print my list that is food. 33 00:02:18,880 --> 00:02:19,240 All right. 34 00:02:19,270 --> 00:02:24,120 So if I print my list I will receive this this answer. 35 00:02:24,130 --> 00:02:29,980 So Hamburger is a juice price let's say for example I want to insert something in my list since lists 36 00:02:30,010 --> 00:02:32,150 can have millions of different elements. 37 00:02:32,320 --> 00:02:35,720 And I'm interested right now to insert one element in this list. 38 00:02:35,820 --> 00:02:40,460 So to be able to do this what I will do I will use the insert function. 39 00:02:40,570 --> 00:02:41,680 So how this function works. 40 00:02:41,680 --> 00:02:42,630 Very simple. 41 00:02:42,700 --> 00:02:46,840 You write down the name of your list dot insert. 42 00:02:48,130 --> 00:02:56,190 Then you will add the index in which you want to insert your your your element. 43 00:02:56,230 --> 00:03:01,060 So let's say for example I am I want to insert another word right here. 44 00:03:01,060 --> 00:03:05,800 So right here will be the element number 2 so 0 1 and 2. 45 00:03:05,800 --> 00:03:08,470 So this will become the element number two. 46 00:03:09,010 --> 00:03:12,610 So the index well the object or the element. 47 00:03:12,610 --> 00:03:19,140 So let's say I am writing so I'm gonna write down the index number two and then I want to insert let's 48 00:03:19,150 --> 00:03:24,700 say in this case I'm interested to insert spaghetti for example. 49 00:03:25,420 --> 00:03:28,800 So spas getting great. 50 00:03:29,200 --> 00:03:35,830 So what I just did is I insert the in the index number to the words spaghetti and if I run my function 51 00:03:36,130 --> 00:03:42,160 if I run my up as you can see I will have hamburger pizza and spaghetti right here and not forget one 52 00:03:42,160 --> 00:03:48,750 thing in Python we always start counting by 0 0 0 1 2 3 4. 53 00:03:49,030 --> 00:03:54,020 So this will become the segment element that we have or the second object. 54 00:03:54,020 --> 00:03:54,520 All right. 55 00:03:54,580 --> 00:03:57,040 So this is the first type of function. 56 00:03:57,040 --> 00:04:02,260 This is the first function we'll talk about the second one will be very simple. 57 00:04:02,500 --> 00:04:04,420 It's simply delete delete. 58 00:04:04,630 --> 00:04:07,930 So let's say you want to delete all your list. 59 00:04:07,930 --> 00:04:10,480 So this list you want to delete it for example. 60 00:04:10,510 --> 00:04:17,470 So what you can do is simply delete everything manually or just write down delete right down the delete 61 00:04:17,470 --> 00:04:18,190 function. 62 00:04:18,190 --> 00:04:20,290 In this case how it will look like. 63 00:04:20,290 --> 00:04:26,370 So let's say for example you write down your food and the word says it it's going to be the clear function. 64 00:04:26,400 --> 00:04:27,460 So very simple. 65 00:04:27,460 --> 00:04:31,350 You write down clear you open and close the parenthesis. 66 00:04:31,420 --> 00:04:40,040 So what we ask Python so as you can see right here we ask Python to clear our func to clear our to clear 67 00:04:40,040 --> 00:04:42,700 our list food. 68 00:04:42,710 --> 00:04:45,440 So here we have our list and we ask Python to clear it. 69 00:04:45,830 --> 00:04:49,880 So when we run the app as you can see we have nothing in our list. 70 00:04:49,880 --> 00:04:54,930 The same thing as if we have deleted everything. 71 00:04:55,200 --> 00:04:55,790 All right. 72 00:04:55,790 --> 00:05:01,240 So right now you know how to add things in your list and how to delete things in your list. 73 00:05:01,400 --> 00:05:04,570 Right now let's say you want to put a list into another list. 74 00:05:04,620 --> 00:05:06,960 I'll just take this out. 75 00:05:07,150 --> 00:05:11,430 So let's say you want to integrate the prices into the foods. 76 00:05:11,460 --> 00:05:13,950 So in this case what will happen. 77 00:05:13,950 --> 00:05:16,020 You want to put those two lists together. 78 00:05:16,020 --> 00:05:19,890 So let's say for example you have one list of food and you have another list of food and you want to 79 00:05:19,890 --> 00:05:24,050 put them all together in one simple list. 80 00:05:24,060 --> 00:05:28,500 So what we'll use as a function to be able to do this there is a function called extend. 81 00:05:28,500 --> 00:05:35,520 So you will simply extend your initial list and add more elements at once so you can add another list 82 00:05:35,520 --> 00:05:39,320 to your first list you can add variables to your list. 83 00:05:39,390 --> 00:05:41,100 So how exactly this works. 84 00:05:41,160 --> 00:05:41,700 Very simple. 85 00:05:41,700 --> 00:05:44,450 So we start with our first list which is food. 86 00:05:45,150 --> 00:05:53,250 So write down food we click on that then the function as I said will be extended so that it will be 87 00:05:53,250 --> 00:05:59,290 this one and what you will write down inside your parentheses will be the second list that you want 88 00:05:59,290 --> 00:05:59,710 to add. 89 00:05:59,710 --> 00:06:03,530 So in this case we want to add the price the prices. 90 00:06:03,910 --> 00:06:09,470 So right now we have our food that extend and the same list. 91 00:06:09,610 --> 00:06:18,430 So if we run our app as you can see the food the food the list the list food became the list food and 92 00:06:18,430 --> 00:06:19,760 the list prices. 93 00:06:19,780 --> 00:06:24,850 So this is a way that you guys can put two lists together simply by using the extend function. 94 00:06:24,880 --> 00:06:26,970 So this is another way that you can. 95 00:06:27,040 --> 00:06:33,590 This is another function that you guys can use to be able to work with lists that you can see it's not 96 00:06:33,590 --> 00:06:36,520 something that is hard to work with. 97 00:06:36,980 --> 00:06:42,100 But once again those are some manipulations that you guys can do with your lists. 98 00:06:42,110 --> 00:06:42,580 All right. 99 00:06:42,860 --> 00:06:46,970 Let's say right now that you guys are interested to find. 100 00:06:47,600 --> 00:06:54,940 Let's say what what is the index of a certain certain type of food right here. 101 00:06:55,040 --> 00:06:59,390 So let's say for example you guys are looking for pizza because here it's simple. 102 00:06:59,390 --> 00:07:02,780 We only have five plus one six elements. 103 00:07:02,780 --> 00:07:07,190 But let's say you have hundreds of elements and you're interested to find one of those. 104 00:07:07,310 --> 00:07:09,400 So it's like in Excel you or you will lose them. 105 00:07:09,440 --> 00:07:13,390 You will use the view lookup function in Python. 106 00:07:13,490 --> 00:07:16,490 What we have we have the index function. 107 00:07:16,520 --> 00:07:19,790 So in this case what you guys will do is very simple. 108 00:07:19,790 --> 00:07:24,590 So we will use our print function and let's say we are looking for pizza. 109 00:07:24,770 --> 00:07:32,070 So what exactly we write down we'll write down our print and what exactly we are asking Python to do. 110 00:07:32,420 --> 00:07:39,560 We will take our list and that from this list will simply write down index. 111 00:07:39,620 --> 00:07:41,320 Our function will be index. 112 00:07:41,480 --> 00:07:44,660 And from here we'll write down the element that we are looking for. 113 00:07:44,660 --> 00:07:47,600 So we are looking for pizza. 114 00:07:47,600 --> 00:07:51,070 We write it down and then we simply run our function. 115 00:07:51,070 --> 00:07:55,340 So as you can see pizza is the first element right here. 116 00:07:55,340 --> 00:07:57,380 So we have zero then we have one. 117 00:07:57,380 --> 00:08:02,750 If we write down another element which in this case will be juice normally we should receive no for 118 00:08:03,710 --> 00:08:07,050 why no sorry. 119 00:08:07,090 --> 00:08:07,480 Why. 120 00:08:07,750 --> 00:08:17,890 Because we have a hamburger as number zero pizza as number one juice as number three and spaghetti as 121 00:08:17,890 --> 00:08:24,110 number two which makes sense because we put it spaghetti right here all right. 122 00:08:24,180 --> 00:08:30,460 Next function that we are going to talk about will be the challenge function. 123 00:08:30,740 --> 00:08:32,990 Let me just show you how it works. 124 00:08:33,030 --> 00:08:38,400 Let's say for example you have one type but what you have right here is the only ones. 125 00:08:38,630 --> 00:08:44,160 But let's say you have pizza five times so what you guys will do simply take the pizza and you can copy 126 00:08:44,250 --> 00:08:47,570 and paste it let's say at the end of the list twice. 127 00:08:48,740 --> 00:08:49,640 All right. 128 00:08:49,700 --> 00:08:56,790 And that will do the same thing for Jews as well so we'll try it multiple times so you guys will understand 129 00:08:56,790 --> 00:08:58,800 how this function works. 130 00:08:58,800 --> 00:08:59,520 All right great. 131 00:08:59,520 --> 00:09:04,710 So right now what we want to do we want to print the number what we want to count the number of times 132 00:09:04,950 --> 00:09:07,640 each of those words is repeated. 133 00:09:07,650 --> 00:09:10,500 So what we will do we'll do this for all the words. 134 00:09:10,530 --> 00:09:16,800 So in this case we have hamburger as well so we just copy and paste it 135 00:09:20,070 --> 00:09:23,960 and we have sushi great. 136 00:09:24,220 --> 00:09:26,360 So yes I have copied and pasted everything. 137 00:09:26,900 --> 00:09:31,070 So what we will do will use a function that is called the count function. 138 00:09:31,160 --> 00:09:37,760 In this case how it's written very simple once and we'll write down our friend function right here and 139 00:09:37,760 --> 00:09:49,630 we will ask Python to go in our list and to count how many times this element is repeated. 140 00:09:49,630 --> 00:09:55,240 So in this case let's say we want to know how many times pizza is repeated and we run our up as you 141 00:09:55,240 --> 00:10:00,750 can see pizza is repeated three times if we want to do the same thing for Jews we can do it 142 00:10:03,660 --> 00:10:09,440 we run our app and as you can see Juice is repeated three times if we do the exact same thing for sushi 143 00:10:09,440 --> 00:10:09,810 is 144 00:10:12,650 --> 00:10:15,700 as you can see it's run two times. 145 00:10:15,810 --> 00:10:20,360 Not forget the eyes it's very important that you write the exact same word right here. 146 00:10:20,360 --> 00:10:26,810 So let's say for example I start to shoot up the letters as you can see it's zero because I don't have 147 00:10:26,870 --> 00:10:30,050 sushi with capital letters right here. 148 00:10:30,110 --> 00:10:34,710 So very important you need to write down the exact the exact word. 149 00:10:34,910 --> 00:10:37,750 If not it's just not gonna work. 150 00:10:37,790 --> 00:10:38,380 All right. 151 00:10:38,510 --> 00:10:46,680 Let's thing we are going to talk about today will be copying lists in this case what we guys. 152 00:10:46,830 --> 00:10:50,830 What you guys want to do let's say for example you want to copy one of those lists. 153 00:10:50,970 --> 00:10:53,330 So it's very simple how this works. 154 00:10:54,710 --> 00:10:57,590 Let's say you want to create another list. 155 00:10:57,590 --> 00:10:59,210 So we'll name it 156 00:11:02,140 --> 00:11:11,180 let's let's name it random random and random will be equal to our food copy. 157 00:11:11,180 --> 00:11:17,100 So in this case food copy so very important you open and close parentheses. 158 00:11:17,100 --> 00:11:20,220 So it will be the copy of the list food. 159 00:11:20,580 --> 00:11:23,250 So in this case we want to have the copy of food. 160 00:11:23,250 --> 00:11:26,130 So we simply write down food that copy. 161 00:11:26,130 --> 00:11:34,470 In this case while it will copy food plus prices that copy. 162 00:11:34,500 --> 00:11:43,980 So what I just did I asked by Don to create another list that will be random that includes the list 163 00:11:44,650 --> 00:11:46,920 of food copy and price copy. 164 00:11:47,160 --> 00:11:52,210 And in this case if I run my app just a print 165 00:12:04,400 --> 00:12:07,360 say I want to print everything. 166 00:12:07,360 --> 00:12:11,560 So in this case I'll print random right. 167 00:12:11,610 --> 00:12:12,570 All right. 168 00:12:12,570 --> 00:12:16,700 So as you can see I have my list right here all my lists. 169 00:12:16,710 --> 00:12:18,800 So I have my first list and I have my second list. 170 00:12:18,810 --> 00:12:22,760 Once again it's another way to well to create a list. 171 00:12:22,770 --> 00:12:30,580 So right now I just copied the food and I copied prices so as you can see guys. 172 00:12:30,580 --> 00:12:33,580 Those are the basic manipulations that you can do with lists. 173 00:12:33,580 --> 00:12:36,220 Those are some basic functions that exist. 174 00:12:36,250 --> 00:12:38,040 You have many many others. 175 00:12:38,230 --> 00:12:43,480 If you guys are interested to learn more about list functions once again I suggest you to simply go 176 00:12:43,510 --> 00:12:45,910 on Internet and type list functions. 177 00:12:45,910 --> 00:12:49,360 You'll have hundreds of them that will appear same thing format functions in some. 178 00:12:49,360 --> 00:12:51,760 Same thing for a string of functions. 179 00:12:51,760 --> 00:12:56,360 But my goal right now is really to show you what exactly are those functions and how they work. 180 00:12:56,470 --> 00:13:01,620 So right now you understand all this and you can go to the next step of our course. 181 00:13:01,660 --> 00:13:02,760 That's it for this class guys. 182 00:13:02,830 --> 00:13:04,690 And see all in our next class.