Set Comprehensions

Set comprehensions are similar to list comprehensions, the only difference is the use of braces {} rather than brackets [] and sets can only contain unique values. They are of the form: my_set = { expression for expression in iterable } You can also add an if condition: my_set = { expression for expression in […]

Sets in Python

The set type is a really useful data structure, it cannot contain duplicate values. It is an unordered collection of objects. It supports: in not in for i in set len() all() any() enumerate() min() max() sorted() sum() Python sets also support mathematical operations including: Subset (x < y) Intersection (x & y) Union (x […]