Python Programming: An Introduction to Computer Science

(Nora) #1
200 CHAPTER11. DATA COLLECTIONS

Set(elements)Createa set(elementsis theinitiallistofitemsintheset).
addElement(x)Addsxtotheset.
deleteElement(x)Removesxfromtheset.
member(x)Returnstrueifxis intheset.
intersection(set2)Returnsa new setcontainingjustthoseelementsthatarecommontothis
setandset2.
union(set2)Returnsa new setcontainingallofelementsthatareinthisset,set2, orboth.
subtract(set2)Returnsa new setcontainingalltheelementsofthissetthatarenotinset2.
Free download pdf