The Python Oracle

Implementing the All / Universal set

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Puddle Jumping Looping

--

Chapters
00:00 Question
00:57 Accepted answer (Score 8)
01:20 Thank you

--

Full question
https://stackoverflow.com/questions/2856...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #set

#avk47



ACCEPTED ANSWER

Score 9


You also need to define the reversed version of the and operator (__rand__) so your subclasses methods get called when it is the second argument as well as the first.

class UniversalSet(set):
    def __and__(self, other):
        return other

    def __rand__(self, other):
        return other