Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
Welcome back.
The methods we're going to talk about when it comes to sets are right here.
It looks like a lot but they're quite similar so hang in there.
I have two sets for us are my set which is one through five and then your set which is four through
10.
Now let's go one by one and see what these methods do.
And if you've ever seen Venn diagrams in your school for example two circles that are overlapping each
other.
What we're about to do is quite similar to this.
The first one is difference and sets are very useful when having two sets and comparing them to each
other.
So for example in here difference simply says my set dot difference and we give it another set such
as your set.
If I print this right here and I click Run I get one two three.
It's going to find the difference of the first.
My set with your set so any duplicates between the two which is four and five gets ignored and it only
shows the difference.
That is one two three.
What's different between my set and your set when viewed from my set.
Well your set doesn't have one two three.
What about the next one discard again if we do my set DOD discard it says it removes an element from
a set if it is a member so here we can say discard five and if I do print my set and I click Run I get
none but if I print here my set and I click Run I get one two three four because we've just discarded
Five it modifies our set just to keep our working space clean I'm going to comment this out next is
difference update so I'm going to say my set and then once again let's see what difference update does
remove all elements of another set from this set.
So if I do your set here and once again I do print and I click Run I get none because it just modifies
my set.
So remember we just have to have our print my set and now this my set is updated with just one two and
three because we're updating it so that the differences are removed.
So four and five are removed unlike difference where it just told you the difference without changing
again if we go back here and simply do my set and I click Run you see that my set here was not modified
right here but then my set bottom was modified because of difference update right.
A few more to go.
Intersection and this one once again my set and in here once again let's see what it does.
It just has intersection with something else.
Well let's find out.
If I do your set here and I do print and I run this it's going to give me four or five because that's
the intersection the two common things that my set and your set has.
What about is this joint well.
If I do my set and then your sect feel like I'm saying those words over and over.
Hopefully that's not too annoying.
And then here if let's comment this out we run this.
I get false is disjoint simply says hey are those two circles overlapping.
Do they have anything in common if for example my said didn't had four didn't have four and five and
I click Run I get true because it's disjointed means these sets have nothing in common.
Awesome.
Just a few more.
The next ones we're gonna see is is subset and is superset but actually before we do that let's do union.
Let's see what this does.
Union will say my set
and in here we want to add the other set your set.
If we print this and click Run I get one two three four five six seven eight nine 10.
What did that just do.
Well union just united these sets together but removed any duplicates.
That's kind of nice.
And as you can see it created a new set for us.
It returned to a new set by the way there's actually a shorthand that you can do here in python which
is the shift and then the key above your enter which is right here the straight line.
So shift and then the backslash.
But if you press shift you'll get this that all straight line.
If you print this will remove the brackets here.
Let's run again and you see that works as well.
And by the way this also exists for intersection.
Again you don't see it that often but with intersection you can do the same thing where you just do
the end.
And if you do that
it gives you the intersection of my set and your set.
All right I promise you this is going to be short.
So two other ones is subset and is superset as you can imagine.
My set if let's say my set only has four and five and I say hey is my set.
Is that a subset of your set.
And I print this if I click Run it's true my set is a subset that is it's inside of the circle of your
set because four and five is inside of it.
So my set the entirety of my set is inside of this other set which we call a subset.
On the other hand we also have this idea of superset.
So if I do instead of is subset is superset I'll get false because while my set is not a superset it
doesn't encompass your set.
It's the other way around.
Your set is a superset of my set
because your set encompasses everything that my set has which is four and five homeboy.
That was a lot.
And you're asking yourself there is no way I'm going to memorize any of that.
Well good.
I don't memorize any of this either.
As a matter of fact I usually go to the Python documentation or just google around and because I know
sets exist if I ever want to compare let's say two sets I know to just go here and find the tool that
I want.
That's the cue of a programmer that I keep mentioning over and over.
It's not memorization.
It's the ability to know that there's tools that you can use.
And being able to Google for them.
I know it doesn't sound exciting because in movies you see everybody typing super fast encoding everything
but that's just not real life in real life.
You just google around find solutions because by now you know what sets are you know what sets can do
so that you can google for methods that are appropriate to your problem.
I'll see you in the next one by.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.