1 00:00:12,300 --> 00:00:18,750 Hello, in this video, we will discuss Satz, which is our third data-collection, after we have successfully 2 00:00:18,750 --> 00:00:21,210 completed lists and dictionaries. 3 00:00:21,870 --> 00:00:26,700 So let's start with a quick example of a a collection. 4 00:00:26,910 --> 00:00:31,410 We have a fruitcake collection here and it starts with curly brackets. 5 00:00:31,590 --> 00:00:35,940 And then we have values inside quotation marks divided by comma. 6 00:00:36,810 --> 00:00:39,630 So it looks a lot like a list. 7 00:00:39,750 --> 00:00:40,290 Right. 8 00:00:40,650 --> 00:00:46,950 But there is a visual difference that we can immediately identify that we're dealing with a set and 9 00:00:46,950 --> 00:00:51,480 not with the list, the curly brackets, the curly brackets. 10 00:00:51,480 --> 00:00:55,130 Give it the way that this is a set and not a list. 11 00:00:55,500 --> 00:01:01,020 And this is the first visual difference between a set and a list. 12 00:01:02,730 --> 00:01:04,590 Which brings me to the next topic. 13 00:01:04,950 --> 00:01:10,170 OK, now we're going to discuss what is what are the differences between lists and set. 14 00:01:10,380 --> 00:01:15,060 And I want to talk about it because it's very important from two reasons. 15 00:01:15,090 --> 00:01:21,330 First of all, once you wanted to use it in your code, you need to know the differences between lists, 16 00:01:21,330 --> 00:01:26,360 dictionaries set and tuple because they were invented for a reason. 17 00:01:26,370 --> 00:01:29,510 They're not just there and they're doing the same thing. 18 00:01:29,520 --> 00:01:31,590 No, they have different purposes. 19 00:01:31,620 --> 00:01:33,600 They have different functionalities. 20 00:01:33,930 --> 00:01:37,530 And you need to know the difference between them in order to use them properly. 21 00:01:38,280 --> 00:01:45,210 Whether you want to become a web developer later on or an information web developer or a backhand developer, 22 00:01:45,210 --> 00:01:45,920 it doesn't matter. 23 00:01:46,170 --> 00:01:49,950 Whoever uses Python is to know the difference between these four items. 24 00:01:50,880 --> 00:01:54,570 So I'm going to discuss it a lot in this case. 25 00:01:54,570 --> 00:02:01,080 We'll discuss this and SAT and maybe further along will compare other data collections as well. 26 00:02:01,800 --> 00:02:04,270 So let's start with the first star. 27 00:02:04,320 --> 00:02:09,420 And a list can contain the same value in several cells. 28 00:02:09,460 --> 00:02:14,730 OK, we can create a list and put, for example, banana, apple, berry and banana again. 29 00:02:14,970 --> 00:02:16,170 There's no problem with it. 30 00:02:16,170 --> 00:02:25,200 So the list gives us this ability to have duplicate items inside our cells, while set collection cannot 31 00:02:25,200 --> 00:02:27,480 have the same value in more than one cell. 32 00:02:28,230 --> 00:02:32,520 Well, it basically can have more than one value. 33 00:02:32,820 --> 00:02:37,770 But if we try to use that value, we will fail to do so. 34 00:02:38,280 --> 00:02:40,710 So, for example, if I put. 35 00:02:42,360 --> 00:02:47,080 Another banana item right here and then I'll try to print it. 36 00:02:47,250 --> 00:02:52,290 I will not see two banana items when I printed, I was the only one banana item. 37 00:02:52,890 --> 00:02:56,940 OK, you understand what I'm going to show this. 38 00:02:57,240 --> 00:03:05,340 This thing is a valuable onion set and it's not available on list, this functionality of remains of 39 00:03:05,340 --> 00:03:13,770 keeping a non duplicate items when using the set so you can put duplicate inside the set. 40 00:03:13,770 --> 00:03:17,260 But once you try to extract it, you will fail to do so. 41 00:03:18,780 --> 00:03:26,730 OK, the different the second difference is liste is in order the collection, meaning he has an index 42 00:03:26,730 --> 00:03:31,140 and cell values can be accessed by index while set in. 43 00:03:31,140 --> 00:03:33,570 The other hand is in an ordered collection. 44 00:03:33,690 --> 00:03:38,980 Same as a dictionary and does not have an index value for each cell. 45 00:03:39,750 --> 00:03:46,560 So as you recall in dictionary, we started the lecture by saying, hey guys, this is an unordered 46 00:03:46,560 --> 00:03:54,480 list, meaning it does not have a index for each cell and list does have a index for each cell. 47 00:03:54,480 --> 00:03:58,560 We can access cell number zero, cell number two or whatever. 48 00:03:59,160 --> 00:04:08,550 While dictionaries and sets does not have this index parameter or index feature, you might say, in 49 00:04:08,550 --> 00:04:08,820 them. 50 00:04:09,810 --> 00:04:18,570 OK, so the third difference we already discussed said is written with curly brackets and in a list 51 00:04:18,900 --> 00:04:22,590 at least we'll use around brackets. 52 00:04:23,930 --> 00:04:29,220 OK, so this is the third difference and the last one inset. 53 00:04:29,400 --> 00:04:33,690 Once an item is created, you cannot change it. 54 00:04:33,880 --> 00:04:42,090 OK, if we try to recall from our lectures regarding lists and dictionaries as well, the same. 55 00:04:42,270 --> 00:04:46,260 So in lists and dictionaries, there's no problem to change the value of the cell. 56 00:04:46,440 --> 00:04:52,960 We can do whatever manipulations upon the inner values they are to change them and without any problem. 57 00:04:52,960 --> 00:04:55,950 But here in said, you cannot change the value. 58 00:04:56,760 --> 00:05:03,570 And I'm sure there are thousands of cases where developers need this feature or they need to create 59 00:05:03,570 --> 00:05:08,130 a certain collection that will be permanent and cannot be changed. 60 00:05:08,340 --> 00:05:12,990 So this is the fourth difference between leased and set. 61 00:05:13,350 --> 00:05:20,370 And before beginning the section, I said there are two reasons and I explained only I explained only 62 00:05:20,370 --> 00:05:20,790 one. 63 00:05:21,150 --> 00:05:24,330 I said only the first reason. 64 00:05:24,330 --> 00:05:29,520 And the second reason is you eventually going to go to interviews, OK? 65 00:05:29,640 --> 00:05:36,210 And once you put the python in your resume, you obviously going to be asked about it. 66 00:05:36,390 --> 00:05:43,370 And this question is really high percent that it will come up because it's a tricky one. 67 00:05:43,410 --> 00:05:43,780 All right. 68 00:05:43,800 --> 00:05:52,560 For example, tell me two differences between a list and a set, and you need to really know your thing 69 00:05:52,770 --> 00:05:57,630 and to know the the difference between them to answer it correctly. 70 00:05:58,050 --> 00:06:00,260 OK, so it's really important to know these things. 71 00:06:00,540 --> 00:06:06,820 This is what makes a difference between a mediocre developer and a a ninja developer. 72 00:06:06,870 --> 00:06:09,870 OK, and I want you to be ninja's by the end of this course. 73 00:06:10,050 --> 00:06:18,030 And this is why I'm giving you this extra information, which is not only like three examples and practice. 74 00:06:18,030 --> 00:06:25,470 You have also additional knowledge here, like background knowledge regarding development and features. 75 00:06:25,770 --> 00:06:27,240 And this is very important. 76 00:06:28,230 --> 00:06:31,050 OK, so one more thing. 77 00:06:31,230 --> 00:06:35,970 As you can see here in the headline, you do not have basics in the title. 78 00:06:36,240 --> 00:06:47,000 And this is because set contains already some elements that we've been walked through in lists and dictionaries. 79 00:06:47,010 --> 00:06:52,720 So this this data collection and theory will be shorter. 80 00:06:53,100 --> 00:06:57,860 OK, there are some topics which are longer, for example, dictionaries and some are shorter. 81 00:06:57,870 --> 00:06:59,460 So this one is a bit shorter. 82 00:07:00,210 --> 00:07:08,580 OK, so now let's head over to the next topic and see some quick manipulations and things that we can 83 00:07:08,580 --> 00:07:09,900 do with set. 84 00:07:10,080 --> 00:07:17,640 OK, so first of all, how to access items in a set so we cannot access a set sell-by index, as we 85 00:07:17,640 --> 00:07:18,720 mentioned already. 86 00:07:18,960 --> 00:07:23,730 But what we can do is to check if it exists by using boolean statement. 87 00:07:24,720 --> 00:07:27,130 And why do I need what do I mean by that? 88 00:07:27,300 --> 00:07:33,060 So if we want to know whether a banana item is inside a set, we should use the following action. 89 00:07:33,130 --> 00:07:39,110 OK, so we have this data collection up here and we have a banana item here inside the cell. 90 00:07:39,660 --> 00:07:41,160 So we want to know whether. 91 00:07:41,200 --> 00:07:46,660 The banana item is inside the set, the set and collection, so we just do the following thing, we 92 00:07:46,660 --> 00:07:50,680 just write a print because we want some output to know if it's there or not. 93 00:07:51,790 --> 00:07:54,280 And then we want to do the following thing. 94 00:07:56,260 --> 00:08:00,590 We want to use the key word in. 95 00:08:01,040 --> 00:08:07,170 OK, so what this means basically is it's a key word, OK? 96 00:08:07,180 --> 00:08:08,410 It's a save the word. 97 00:08:09,100 --> 00:08:13,590 And this word means like a question mark for us. 98 00:08:13,600 --> 00:08:20,500 I'm saying it for us to understand, like those banana is in fruits, that collection. 99 00:08:21,400 --> 00:08:24,220 The answer is Boolean is a boolean value. 100 00:08:24,220 --> 00:08:25,790 So it's a true or false value. 101 00:08:25,810 --> 00:08:32,050 So in this case, banana is in fruit collection, so the output will be true. 102 00:08:32,400 --> 00:08:38,980 OK, so this is how you verify for certain element is inside the set collection. 103 00:08:39,700 --> 00:08:40,150 All right. 104 00:08:40,360 --> 00:08:43,960 Our following topics will be Loop's and using Loop's. 105 00:08:43,960 --> 00:08:51,550 We can extract all the values out of every data-collection, but we haven't studied Lupe's yet. 106 00:08:51,790 --> 00:08:59,380 So here you can only just verify this point, only verify for certain items inside the set for there 107 00:08:59,380 --> 00:08:59,580 aren't. 108 00:08:59,590 --> 00:09:05,470 We'll learn how to extract values further in the next videos. 109 00:09:05,710 --> 00:09:15,430 OK, so next in line is how to delete items of a set so we can remove items from a set by using the 110 00:09:15,430 --> 00:09:17,890 remove action or the discard action. 111 00:09:18,820 --> 00:09:20,670 So basically they are the same. 112 00:09:21,010 --> 00:09:22,990 So it's really simple. 113 00:09:23,140 --> 00:09:31,120 You just mention the SEP collection, then use the remove action keyword and then use the item that 114 00:09:31,120 --> 00:09:32,240 you want to remove. 115 00:09:33,590 --> 00:09:43,060 OK, and now let us see how to add items to a set, OK, so we can only add or remove items, but we 116 00:09:43,060 --> 00:09:48,310 cannot change items so we can remove items from SL. 117 00:09:49,490 --> 00:10:00,800 By using sorry, we can add items to it to a set collection by using the action would add or update. 118 00:10:00,880 --> 00:10:07,700 OK, they are the same, so just mention the sad collection and then use the add keyword and use the 119 00:10:07,700 --> 00:10:09,350 value that you want to add. 120 00:10:10,220 --> 00:10:11,230 It's pretty simple, right? 121 00:10:13,290 --> 00:10:19,770 OK, and one last thing, as we already discussed, regarding duplicates. 122 00:10:21,210 --> 00:10:24,780 All right, so let's see the following example. 123 00:10:25,210 --> 00:10:28,920 OK, so we will have duplicate items inside that. 124 00:10:29,160 --> 00:10:35,790 Once printing it, Python will ignore duplications and will print only one of the duplicated items. 125 00:10:36,180 --> 00:10:37,400 So a quick example. 126 00:10:37,470 --> 00:10:41,120 Once having this set collection will try to print it. 127 00:10:41,370 --> 00:10:42,590 But pay attention. 128 00:10:42,600 --> 00:10:45,310 You have banana and another banana right here. 129 00:10:46,200 --> 00:10:49,950 So if we print it out, we will have only one banana value. 130 00:10:50,760 --> 00:10:51,240 All right. 131 00:10:51,480 --> 00:11:00,870 I cannot assure you that the first item will be printed all the time because Python arranges its memory 132 00:11:00,870 --> 00:11:03,720 inside our computer in a certain way. 133 00:11:03,910 --> 00:11:08,730 And as we mentioned earlier, this is an unordered list. 134 00:11:08,910 --> 00:11:12,800 So there's no indexes here for zero one two. 135 00:11:12,840 --> 00:11:15,050 There's no such thing. 136 00:11:15,270 --> 00:11:22,110 So we cannot assure that this value always will be printed and this value will be ignored. 137 00:11:22,290 --> 00:11:30,810 But we can assure that only one of the banana items would be printed out as circulation does not tolerate 138 00:11:31,050 --> 00:11:32,310 duplications. 139 00:11:33,600 --> 00:11:38,970 OK, this it covers about the theory regarding said. 140 00:11:39,270 --> 00:11:45,140 And let us go to the next video and see some examples in the code. 141 00:11:46,140 --> 00:11:46,680 All right. 142 00:11:46,930 --> 00:11:47,510 Bye bye.