Learning Resources


Sets are unordered collections of simple objects. These are used when the existence of an object in a collection is more important than the order or how many times it occurs.

Using sets, you can test for membership, whether it is a subset of another set, find the intersection between two sets, and so on.

>>> bri = set(['brazil', 'russia', 'india'])
>>> 'india' in bri
>>> 'usa' in bri
>>> bric = bri.copy()
>>> bric.add('china')
>>> bric.issuperset(bri)
>>> bri.remove('russia')
>>> bri & bric # OR bri.intersection(bric)
{'brazil', 'india'}

How It Works:

The example is pretty much self-explanatory because it involves basic set theory mathematics taught in school.