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
setconstructor from any iterableinoperator is very fast (set is implemented as hash table)- subset and superset comparisons with
>=operators - update methods (
updateadd items from iterable,intersection_updateintersects 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