pythonsetmathematical-lattices

Python set intersection and neutral top/greatest element


Does python have a neutral set (, in terms of being the neutral element of intersection) or sort of lattice top/greatest set that works with basic python sets?

What I mean is the following

{1,2,3} & topset

simply returns {1,2,3} and

{1,2,3} | topset

returns topset.

(Also I would be happy if you could direct me to an older post if this question has already been asked, but I can't find any)


Solution

  • The website 'Trails in a Langscape' contains an implementation of a universal set. You might want to use that implementation, or extract contents that you need for your implementation.

    Basically what they do is implement operator-functions (such as __radd__, __add__, etc...).