1 00:00:12,440 --> 00:00:13,760 Hi, everybody, and welcome. 2 00:00:13,790 --> 00:00:19,490 So we have completed successfully the valuable part of the course, and today we're going to begin a 3 00:00:19,490 --> 00:00:22,730 whole new topic that will last several lectures. 4 00:00:23,600 --> 00:00:30,080 We will learn about our collections and quickly comparing collections to variables. 5 00:00:30,590 --> 00:00:38,480 So variables, a variable, any type of variable, it can contain only one value inside it, as we studied 6 00:00:38,480 --> 00:00:39,500 in the last lectures. 7 00:00:39,770 --> 00:00:47,000 And the difference between a collection and a variable is that the collection can contain several values 8 00:00:47,000 --> 00:00:52,700 inside or even a lot of values inside as we wish. 9 00:00:52,940 --> 00:00:56,300 So this is the difference between a variable and a collection. 10 00:00:57,470 --> 00:01:01,090 So collection is like a headline inside the collections. 11 00:01:01,640 --> 00:01:03,880 We have four types of collections. 12 00:01:04,580 --> 00:01:14,360 But before let's just let me just say that collection is a container that store several items of values 13 00:01:14,360 --> 00:01:23,210 inside and we will begin by the definition of collections and then go over to the first one, which 14 00:01:23,210 --> 00:01:27,460 is a list, which is the first type of collection that we're going to study. 15 00:01:28,310 --> 00:01:34,940 So using these collections, we can store any type of data that is related in some manner. 16 00:01:36,200 --> 00:01:41,900 What that means basically that in our code, when we have several values that are connected in some 17 00:01:41,900 --> 00:01:46,640 way, we would like to create a collection and store them all inside the collection. 18 00:01:47,270 --> 00:01:53,690 Instead of having, for example, five variables, we can make one collection and put the items one 19 00:01:53,690 --> 00:01:55,370 after the other in this collection. 20 00:01:56,300 --> 00:02:04,280 So starting from this point, A, I will lose the term collections and I'll start using the term list 21 00:02:04,490 --> 00:02:08,380 because this is the first collection type that we're going to study. 22 00:02:08,750 --> 00:02:14,180 And in the following next year, of course, we will go over a dictionary set and tuple. 23 00:02:14,720 --> 00:02:20,430 And each of these will contain three parts, same as the very variable part. 24 00:02:20,750 --> 00:02:23,680 First part is three is what we're studying right now. 25 00:02:23,900 --> 00:02:28,120 The second part will be examples in the code and the third part will be practice. 26 00:02:28,490 --> 00:02:33,500 So hang on, guys, and B, be brave. 27 00:02:33,500 --> 00:02:37,310 And as long as you'll listen and as long as you practice, you will be fine. 28 00:02:37,400 --> 00:02:38,180 We'll be just fine. 29 00:02:39,030 --> 00:02:39,320 All right. 30 00:02:39,330 --> 00:02:44,060 So let's begin, for example, let's just give a quick example of a list. 31 00:02:44,060 --> 00:02:51,800 For example, I can prepare a list of ages that inside I can put ages which are divided with a comma. 32 00:02:52,250 --> 00:02:59,690 I can make a collection of fruits and put names of fruits inside the collection, a banana, an apple 33 00:02:59,890 --> 00:03:02,170 and a watermelon and so on. 34 00:03:02,930 --> 00:03:07,940 So these collections has have something in comment regarding their values. 35 00:03:08,290 --> 00:03:08,620 All right. 36 00:03:09,470 --> 00:03:14,210 So let's begin by starting with the first collection type, which is a list. 37 00:03:15,020 --> 00:03:18,680 So let's go over the characteristics of a list. 38 00:03:20,030 --> 00:03:20,410 All right. 39 00:03:20,420 --> 00:03:27,680 So in Python, Aliased is created by placing all the values or in other words, elements inside square 40 00:03:27,680 --> 00:03:29,210 brackets as so. 41 00:03:30,090 --> 00:03:36,050 All right, so these square brackets mean that this is a list. 42 00:03:36,570 --> 00:03:41,490 All right, so the values inside should be separated by commas between each value. 43 00:03:42,180 --> 00:03:47,340 And the second thing is that aliased can have any number of values. 44 00:03:47,610 --> 00:03:54,360 You can put one value inside two values, one hundred values or a thousand values as you wish. 45 00:03:55,860 --> 00:03:57,390 So it doesn't have any limit. 46 00:03:57,790 --> 00:04:05,750 And also this can contain and mixed types of values inside integers, float's strings and so on. 47 00:04:05,940 --> 00:04:10,420 So you can mix types of variables inside the collection. 48 00:04:10,650 --> 00:04:12,830 There is no limitation for that as well. 49 00:04:13,620 --> 00:04:18,470 So let's go quickly straightforward to a quick example of several collections. 50 00:04:18,870 --> 00:04:22,550 So the first one is creation of a list. 51 00:04:22,800 --> 00:04:27,570 So this is how this looks like we just create a variable. 52 00:04:29,060 --> 00:04:36,280 And then we separate the words with an underline, like we studied until this point, then we do equals 53 00:04:36,290 --> 00:04:41,930 and then here we put square brackets and there you go, we have our first list. 54 00:04:42,830 --> 00:04:50,300 So and the next one in line is just as we talked right here, when you want to insert items inside the 55 00:04:50,300 --> 00:04:57,140 list, just inside the square brackets, you can put values divided by commas and at the end closet 56 00:04:57,140 --> 00:04:58,530 it with this square bracket. 57 00:04:58,850 --> 00:04:59,200 All right. 58 00:04:59,840 --> 00:05:08,060 So as we mentioned, let's go to the last one in line, as we mentioned, at least, can contain several 59 00:05:08,060 --> 00:05:09,790 types of values inside. 60 00:05:10,100 --> 00:05:14,090 So we have a list here that contains a string. 61 00:05:15,210 --> 00:05:22,260 All right, contains a sorry, not a string, it's an integer and then a string and then a float all 62 00:05:22,260 --> 00:05:23,460 together combined. 63 00:05:23,580 --> 00:05:24,590 That's just fine. 64 00:05:24,600 --> 00:05:26,130 We won't get an error for that. 65 00:05:27,750 --> 00:05:34,800 And now that we know how collection looks like and we know several things about it, that he has an 66 00:05:34,800 --> 00:05:39,780 endless number of cells that we can use, we can mix types in that. 67 00:05:40,050 --> 00:05:49,500 So now let's try to pull out the values out of the list, meaning if we created a list so later around 68 00:05:49,500 --> 00:05:54,760 the code, we would like to extract, for example, this value and use it or maybe print it. 69 00:05:55,080 --> 00:05:56,760 We don't need the other values. 70 00:05:56,760 --> 00:05:59,160 We just need this one, the two, for example. 71 00:06:00,060 --> 00:06:01,440 So let's study. 72 00:06:01,440 --> 00:06:05,430 How can we extract data from the collection? 73 00:06:06,570 --> 00:06:06,990 All right. 74 00:06:07,260 --> 00:06:15,360 So before we continue, I just want to say that this lecture will have two or maybe three parts as it's 75 00:06:15,360 --> 00:06:16,710 a pretty big one. 76 00:06:17,100 --> 00:06:20,940 I'm talking only about the lists and for the further on as well. 77 00:06:21,240 --> 00:06:25,200 But this is the lecture part one of lists. 78 00:06:25,620 --> 00:06:28,050 So let's continue. 79 00:06:28,470 --> 00:06:33,880 OK, so how can we access a value in a list? 80 00:06:34,260 --> 00:06:41,040 So basically there are two ways to access a value in the list or in other words, to extract the value 81 00:06:41,040 --> 00:06:41,680 from the list. 82 00:06:42,180 --> 00:06:50,310 So the first way is by accessing the the values inside the list by index so we can use. 83 00:06:52,480 --> 00:06:57,970 All right, we can use the index of this value to access it. 84 00:07:02,680 --> 00:07:03,940 It's supposed to be, but. 85 00:07:07,010 --> 00:07:15,230 But it's important to remember that the first value would have the index to zero and not one will see 86 00:07:15,230 --> 00:07:16,720 an example in a few seconds. 87 00:07:18,170 --> 00:07:22,430 So just let's go over what we just read. 88 00:07:22,460 --> 00:07:28,100 So if we have, for example, here, how many values do we have in this? 89 00:07:28,490 --> 00:07:30,680 Let we just put it small. 90 00:07:31,940 --> 00:07:33,220 We have here value. 91 00:07:33,230 --> 00:07:34,430 Number one value. 92 00:07:34,460 --> 00:07:35,900 Number two, value. 93 00:07:35,930 --> 00:07:38,370 Number three, four and five. 94 00:07:38,780 --> 00:07:41,720 So the index meaning the police. 95 00:07:42,170 --> 00:07:43,070 The police. 96 00:07:43,400 --> 00:07:43,890 All right. 97 00:07:44,240 --> 00:07:45,310 Of the value. 98 00:07:45,350 --> 00:07:46,360 This is the index. 99 00:07:46,730 --> 00:07:49,850 So this will be the first place. 100 00:07:50,150 --> 00:07:52,640 I'm saying literally it's first. 101 00:07:52,940 --> 00:07:57,760 But as we just read right here, it will be index number zero. 102 00:07:58,520 --> 00:07:59,010 All right. 103 00:07:59,390 --> 00:08:06,860 So it doesn't the counting of this and then this and then this and so on doesn't start for one. 104 00:08:07,130 --> 00:08:08,490 It starts from zero. 105 00:08:08,520 --> 00:08:16,280 So the index of this value zero and the value and the index of this value is one and the index of these 106 00:08:16,280 --> 00:08:18,430 values two and so on. 107 00:08:18,440 --> 00:08:19,550 You can see right here. 108 00:08:21,030 --> 00:08:30,930 So once we want to access any of the values in the list, we can access it by pulling it out, using 109 00:08:31,170 --> 00:08:36,540 the index of it, and we will see in just a second how to do it. 110 00:08:38,910 --> 00:08:41,220 Also, a really important note. 111 00:08:41,880 --> 00:08:48,630 Once we try to access other indexes, then these we will raise an index arrowroot. 112 00:08:48,720 --> 00:08:56,250 So, for example, if we try to access the index number five or index number 52 or index number twenty 113 00:08:56,250 --> 00:09:02,730 seven, for example, we will have an error because we have in total only the index is from zero to 114 00:09:02,730 --> 00:09:05,610 fall, then from zero to four. 115 00:09:05,610 --> 00:09:13,410 So filled in and all other indexes in the world are not contained in this list. 116 00:09:15,280 --> 00:09:23,950 And also, we have a second way to access the values of the list, and the second way is by negative 117 00:09:23,950 --> 00:09:28,040 indexing and let's see how we do it. 118 00:09:28,360 --> 00:09:28,710 All right. 119 00:09:28,720 --> 00:09:31,300 So Python allows us to use Axis. 120 00:09:32,780 --> 00:09:34,070 I don't allows us. 121 00:09:35,490 --> 00:09:36,120 To. 122 00:09:37,200 --> 00:09:38,820 Access the values. 123 00:09:41,070 --> 00:09:48,900 Starting at the end of the list by adding the prefix minus to it, in other words, the index minus 124 00:09:48,900 --> 00:09:54,430 one is referring to the last item off the list, which is yes. 125 00:09:55,260 --> 00:09:55,850 All right. 126 00:09:56,070 --> 00:09:58,080 So we have the list, by the way. 127 00:09:58,320 --> 00:10:01,300 It's the same list that just copied it so it would be easier. 128 00:10:01,650 --> 00:10:04,020 So we have the list. 129 00:10:04,740 --> 00:10:12,120 And if we want to access to the we want access to the last item of it, we will use the index minus 130 00:10:12,120 --> 00:10:12,520 one. 131 00:10:12,810 --> 00:10:19,350 So once we add the minus prefix to the index, it means give me the last one. 132 00:10:20,070 --> 00:10:22,530 You mean the last item of your list? 133 00:10:23,130 --> 00:10:31,050 And if we use a minus two index, we will get to the before last value in the list and so on. 134 00:10:32,490 --> 00:10:42,060 So let's go over with a few examples just to get the hang of it, of of access by index and access by 135 00:10:42,060 --> 00:10:43,440 negative indexing. 136 00:10:44,850 --> 00:10:46,670 So we have the list right here. 137 00:10:47,250 --> 00:10:51,150 And let's try to print out several values out of it. 138 00:10:51,540 --> 00:10:53,910 Just zoom out a little bit so we can see the list as well. 139 00:10:54,960 --> 00:10:55,280 All right. 140 00:10:55,290 --> 00:11:03,350 So let's try to what happens when we try to print the value in the index zero, right. 141 00:11:03,400 --> 00:11:03,880 By the way? 142 00:11:04,080 --> 00:11:07,860 This is the way to access values by their index. 143 00:11:08,070 --> 00:11:15,240 You just write the name of your list and then put square brackets and put a number inside. 144 00:11:15,240 --> 00:11:18,810 The number that you will put will be the index value. 145 00:11:19,950 --> 00:11:24,580 And it will extract for you the value of the cell itself. 146 00:11:25,710 --> 00:11:29,280 So once we print the name of the list. 147 00:11:30,360 --> 00:11:34,230 Once we print the name of the list, by the way, I need to change it because it's not the name of my 148 00:11:34,230 --> 00:11:34,560 list. 149 00:11:37,510 --> 00:11:45,120 Once we take once we print the name off the list and put zero in square brackets, put zero inside, 150 00:11:45,130 --> 00:11:48,740 so let's go further, let's go up and the page. 151 00:11:48,760 --> 00:11:54,300 So once we print the zero index of the list, we will get an output of thirty one. 152 00:11:54,400 --> 00:11:54,780 All right. 153 00:11:54,790 --> 00:11:57,310 So here it will be. 154 00:12:00,570 --> 00:12:09,990 Outpoured 31, and once we won the third one, so basically this is zero, this is one. 155 00:12:10,260 --> 00:12:11,100 This is too. 156 00:12:11,550 --> 00:12:12,330 And this is three. 157 00:12:14,900 --> 00:12:21,740 So the three, the third the next on the list would give us the output. 158 00:12:23,200 --> 00:12:26,900 Three, so have a look again. 159 00:12:26,950 --> 00:12:31,840 This is the number zero index, this is index number one. 160 00:12:31,840 --> 00:12:35,950 This is index number two and this is index number three. 161 00:12:36,490 --> 00:12:39,140 If we go up, we can see it here as well. 162 00:12:39,580 --> 00:12:42,550 So this is the index value. 163 00:12:44,060 --> 00:12:46,830 And this is the value inside the list. 164 00:12:46,870 --> 00:12:48,210 This is the sale value. 165 00:12:48,500 --> 00:12:50,120 So this is on industry. 166 00:12:50,130 --> 00:12:51,230 We're going to value three. 167 00:12:52,820 --> 00:12:56,180 So let's go quickly on the negative ones as well. 168 00:12:56,810 --> 00:13:05,090 So we have here index number minus two, meaning we have the list right here or that this is index also, 169 00:13:05,090 --> 00:13:06,400 by the way, it's the same list. 170 00:13:06,420 --> 00:13:15,110 So this is index number zero and also index number minus five, because when we had the minus, we start 171 00:13:15,110 --> 00:13:23,130 counting counting from the last one and then the numbers go up as we go to the beginning. 172 00:13:24,590 --> 00:13:32,420 So if we try to print what's inside index number minus two, we get the value of three. 173 00:13:34,460 --> 00:13:44,630 So not noticed this number three index and number minus two index give us the same output you see. 174 00:13:44,810 --> 00:13:46,820 So this is the index. 175 00:13:47,800 --> 00:13:52,600 So this is the index minus to the values three go up. 176 00:13:53,860 --> 00:13:57,130 This is the index number three and the values story as well. 177 00:13:57,910 --> 00:13:58,420 All right. 178 00:13:58,430 --> 00:13:59,980 So all right. 179 00:13:59,980 --> 00:14:01,120 So let's go further. 180 00:14:04,390 --> 00:14:13,660 And unindexed, my minus one, we get the value, yes, and index number seven, we don't have one because 181 00:14:13,660 --> 00:14:17,740 our index is going up from zero to four and that's it. 182 00:14:18,250 --> 00:14:25,300 So we get an index arrow because we do not have this index. 183 00:14:25,780 --> 00:14:26,080 All right. 184 00:14:26,090 --> 00:14:30,120 So, guys, I think that's about it dealing with theory. 185 00:14:30,730 --> 00:14:32,560 So a quick overview. 186 00:14:32,980 --> 00:14:36,290 We explain that we have collections on Titan. 187 00:14:36,430 --> 00:14:40,390 It's a special module, a library, if you want to say so. 188 00:14:40,390 --> 00:14:47,470 We have four types of collections and python list dictionaries set and tuple. 189 00:14:47,710 --> 00:14:54,820 We started with the first one, which is list we want went over the definition of it and the characteristics 190 00:14:54,820 --> 00:14:56,560 it has here. 191 00:14:56,710 --> 00:15:03,220 We learned how to declare in your list how to put items inside the list, and the list can contain mixed 192 00:15:03,220 --> 00:15:04,930 types of variables inside. 193 00:15:05,350 --> 00:15:12,970 And then we'll learn how to access values using their index by using a straightforward index and also 194 00:15:12,970 --> 00:15:15,370 by negative indexing with a few examples. 195 00:15:15,790 --> 00:15:24,940 So let's meet in the next lecture when we try to see various examples on each arm and afterwards will 196 00:15:24,940 --> 00:15:26,860 be the practice part. 197 00:15:27,520 --> 00:15:29,320 And that's about eight guys.