00:00If you guys have studied Sets, you must've read Set Theory
00:03which says "Set is a collection of well-defined objects."
00:07Now, everything in python is an object, and if you all
00:09want a data entry in python with no repeated entries
00:14you can make a set, let me give you a good example
00:17Imagine you need to collect a list of people whose names start with an 'S'
00:23and you go to different people and ask their names,
00:25some say 'Shruti', some 'Samarth', and some 'Shubham'
00:29maybe one of your friends repeats the name 'Shubham'
00:32and you may not want to add this to the list because
00:35if 100 people say 'Shubham', there'll be 100 Shubham in the list.
00:38And if you want the list that you're making to have no repetitions,
00:43We can make 'SETS' for this.
00:44Let's see the methods of sets and why it's used.
00:48So hop onto the computer screen and
01:00Many of you may have learned in maths that
01:02Set is a collection of well-defined objects.
01:04Well, sets in python are the same too.
01:07Now what's the meaning of set, why is it in python
01:10Sometimes we collect certain values which we don't want to get repeated.
01:16Imagine I ask you, the employee IDs of those
01:20who have already received a gift
01:23Now you're asked to report who has received a gift
01:28Imagine there's a company that wants to give a thanksgiving gift once,
01:32and you need to insure that no one receives a gift more than once.
01:35So every employee with gifts is asked to submit their IDs.
01:40Now, if we solve this problem through a list, it will be very big
01:44and it will have repeated values
01:45One employee may take the name of 5 other employees,
01:48and the other employee repeats the same exact 5 names.
01:51Or takes 3 out of the 5 names
01:54This will increase the size of the list
01:56and more memory will be used, which we don't want
01:58That's why there's Set data type inside python.
02:02So how do we make Set?
02:03So, If I write s={2,4,2,6} and print it.
02:11In 's' you'll see 2 is being repeated twice but
02:15the set will take it only once.
02:17So, {2,4,2,6} will be {2,4,6} as you can see., okay.
02:22This shows Set doesn't take repeated values.
02:25So this is a Set of well-defined objects as we know
02:28Set is a collection of well-defined objects, right.
02:30And if I talk about Set here
02:33There are many methods to it, you can add values
02:37You can do everything that you can do with a list, in a very similar fashion
02:41except for the fact that there's no value repetition, okay.
02:44So, sets are unordered collections of data items.
02:47Here the word 'unordered' is very important, because
02:49it does not maintain order.
02:51You can't hope that if 2 comes first then 4, 6 would come next.
02:55There's no guarantee of maintaining this order.
02:58This is something you all need to remember.
03:00Set items are separated by commas and enclosed within curly brackets {}.
03:04As I have done here, values are separated by commas and
03:07instead of the square brackets that we use in our lists,
03:11or parentheses (), that we use in Tuple,
03:14here we use curly brackets, kind of like this.
03:17Through this python interpreter understands that we're talking about sets.
03:21Sets are unchangeable meaning you can't change items of a set
03:25once they are created.
03:26And sets don't contain duplicate items.
03:29Now let's understand this,
03:30'Sets are unchangeable' which means
03:32that I can't put 8 in place of 2.
03:37Once 2 go in the set; consider this a very big bag
03:41which has many pearls in it, if you put one more, it gets mixed.
03:46you can't find it and replace it anymore.
03:49Understand it kind of like that.
03:51Just as lists have different kinds of data entries, Sets can have them too
03:59Now see, 'Carla', 19, false, 5,9, 19
04:02since 19 is repeated it'll come once.
04:04Now 19 can come at the start or at the end.
04:07Python doesn't guarantee maintained order.
04:10This you should know. Now as you can see, this is the output.
04:13But in my case, this is the output. Hence no guarantee for order.
04:16Now, as you can see, when I ran the code, this was the output.
04:21But now, this is the output, okay.
04:25Hence no guarantee for order, anything can be put anywhere.
04:29You can't say that you'll get a maintained order.
04:33There's no guarantee, okay.
04:35Here we see that items of the set occur in random order.
04:39And hence, they can't be accessed using index numbers.
04:41You can't do that, info 0, info 1, or info 2. No.
04:45They don't maintain order, okay.
04:48Also, sets don't allow duplicate values, which we already saw.
04:52Now the quick quiz may blow your mind.
04:55Some of you maybe or all.
04:56Try to create an empty set, and check using the type function.
05:00Whether the type of your variable is a set or not.
05:03Imagine I make a set named 'Harry' & how you'll have to see.
05:07After that, it should be an empty set
05:09After this, I'll print 'type of harry', okay.
05:14Now, if you'll print type of harry, you must get a set.
05:17A lot of you people will do this.
05:20Or pause the video & tell me in the comment section what code you wrote.
05:24Now, if you wrote this code, it's absolutely wrong.
05:26Because you'll see when you do this,
05:30even you'll get shocked, that why did it become a dictionary.
05:32I tried making a set. So always remember in your life,
05:36that the syntax for set and dictionary bot start and end with a curly bracket.
05:43That's why doing this gives you an empty dictionary not set.
05:47That's why to make an empty set, we need set like this
05:52This is how we make an empty set and now our type will be set.
05:57Here you can see, class set.
05:58You should know this. A lot get confused but let me tell you,
06:02If you need to make an empty set, this is how you do it.
06:07Now let me tell you how to access set items.
06:10One way through For loop, I can say
06:16Print value and that's it.
06:19You can use For in-loop and running this will
06:22Carla, 19, etc in any order
06:25Why did I say any order? Because Set doesn't maintain order.
06:29Set's work is, putting value in a bag, with no repetitions.
06:33Imagine you put 2 iPhones in a bag, and it'll become 1 iPhone.
06:37You lost 1 iPhone. That's why, whenever you add values to a set
06:43You'll never see repetitions.
06:47You should know this.
06:49Now you can see, my output is different, here output is different,
06:52and maybe different output when you run it.
06:53This is because python doesn't give us maintained order in set.
07:00This is something you should know.
07:02Now, if you haven't accessed this playlist, sure do.
07:06because in the next video I'll tell you about more Set facts
07:09In sets I'll tell you what are the methods
07:13How union intersection is found, if you have studied set theory,
07:16You'll understand what I'm talking about.
07:18And if you haven't studied, meet me in the next video.
07:20What is a union or intersection, I'll clear it in the next video.
07:24That's all for this video, guys.
07:26If you haven't accessed the playlist, bookmark and save it.
07:28Thank you so much guys, for watching this video.
07:30AND I WILL SEE YOU NEXT TIME!!