set
2023-05-13 python set collections union intersection comparison youtubeThe set is one of most powerful concepts in python. I recently watched following video
Slides are available at speakerdeck. Here are my notes from the watching
- the set is not mere container for unique elements
- there is many powerful operations working over whole sets
- intersection works similarly to
and
, operator&
in python - union is basically
or
, operator|
in python - symmetric difference compares to
xor
, items in each sets, but not both, operator^
in python - difference - things in first that are not in second, operator
-
in python
- intersection works similarly to
- way to build set from series - set comprehension
set
constructor from any iterablein
operator is very fast (set is implemented as hash table)- subset and superset comparisons with
>=
operators - update methods (
update
add items from iterable,intersection_update
intersects with iterable) - the interface is defined in collections.abc, most of set operations are defined there
- praise for the book Go Programming Language by Alan Donovan and Brian Kernighan
- demonstration of writing alternate set of unsigned integers, available on github