Author Dusty Phillips Reviewers


All: {'Sarah Brightman', "Guns N' Roses", 'Vixy and Tony'



Download 2,95 Mb.
Pdf ko'rish
bet170/183
Sana20.07.2022
Hajmi2,95 Mb.
#831085
1   ...   166   167   168   169   170   171   172   173   ...   183
Bog'liq
python3-oop

All: {'Sarah Brightman', "Guns N' Roses", 'Vixy and Tony',
'Savage Garden', 'Opeth', 'Nickelback'}
Both: {"Guns N' Roses"}
Either but not both: {'Savage Garden', 'Opeth', 'Nickelback',
'Sarah Brightman', 'Vixy and Tony'}
These methods all return the same result, regardless of which set calls the other.
We can say 
my_artists.union(auburns_artists)
or 
auburns_artists.
union(my_artists)
and get the same result. There are also methods that return 
different results depending on who is the caller and who is the argument.
These methods include 
issubset
and 
issuperset
, which are the inverse of each 
other. Both return a 
bool
. The 
issubset
method returns 
True
, if all of the items in 
the calling set are also in the set passed as an argument. The 
issuperset
method 
returns 
True
if all of the items in the argument are also in the calling set. Thus 
s.issubset(t)
and 
t.issuperset(s)
are identical. They will both return 
True
if 
t
contains all the elements in 
s
.
www.it-ebooks.info


Python Data Structures
[
 176 
]
Finally, the 
difference
method returns all the elements that are in the calling set, 
but not in the set passed as an argument; this is like half a 
symmetric_difference

The 
difference
method can also be represented by the 
-
operator. The following 
code illustrates these methods in action:
my_artists = {"Sarah Brightman", "Guns N' Roses",
"Opeth", "Vixy and Tony"}
bands = {"Guns N' Roses", "Opeth"}
print("my_artists is to bands:")
print("issuperset: {}".format(my_artists.issuperset(bands)))
print("issubset: {}".format(my_artists.issubset(bands)))
print("difference: {}".format(my_artists.difference(bands)))
print("*"*20)
print("bands is to my_artists:")
print("issuperset: {}".format(bands.issuperset(my_artists)))
print("issubset: {}".format(bands.issubset(my_artists)))
print("difference: {}".format(bands.difference(my_artists)))
This code simply prints out the response of each method when called from one set
on the other. Running it gives us the following output:

Download 2,95 Mb.

Do'stlaringiz bilan baham:
1   ...   166   167   168   169   170   171   172   173   ...   183




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish