Say I have a finite iterable X
and an equivalence relation ~
on X
. We can define a function my_relation(x1, x2)
that returns True
if x1~x2
and returns False
otherwise. I want to write a function that partitions X
into equivalence classes. That is, my_function(X, my_relation)
should return a list of the equivalence classes of ~
.
Is there a standard way to do this in python? Better yet, is there a module designed to deal with equivalence relations?