def equivalence_classes(iterable, relation):
 blocks = []
 for y in iterable:
  for block in blocks:
   x = arbitrary_element(block)
   if relation(x, y):
    block.append(y)
    break
  else:
   blocks.append([y])
 return {frozenset(block) for block in blocks}

def equivalence_classes ( iterable , relation ) : blocks = [ ] for y in iterable : for block in blocks : x = arbitrary_element ( block ) if relation ( x , y ) : block . append ( y ) break else : blocks . append ( [ y ] ) return { frozenset ( block ) for block in blocks }
returns the set of equivalence classes of the given iterable under the specified equivalence relation .