def pairwise_most_common(sets):
 from sympy.utilities.iterables import subsets
 from collections import defaultdict
 most = (-1)
 for (i, j) in subsets(list(range(len(sets))), 2):
  com = (sets[i] & sets[j])
  if (com and (len(com) > most)):
   best = defaultdict(list)
   best_keys = []
   most = len(com)
  if (len(com) == most):
   if (com not in best_keys):
    best_keys.append(com)
   best[best_keys.index(com)].append((i, j))
 if (most == (-1)):
  return []
 for k in range(len(best)):
  best_keys[k] = (best_keys[k], best[k])
 best_keys.sort(key=(lambda x: len(x[1])))
 return best_keys

def pairwise_most_common ( sets ) : from sympy . utilities . iterables import subsets from collections import defaultdict most = ( - 1 ) for ( i , j ) in subsets ( list ( range ( len ( sets ) ) ) , 2 ) : com = ( sets [ i ] & sets [ j ] ) if ( com and ( len ( com ) > most ) ) : best = defaultdict ( list ) best_keys = [ ] most = len ( com ) if ( len ( com ) == most ) : if ( com not in best_keys ) : best_keys . append ( com ) best [ best_keys . index ( com ) ] . append ( ( i , j ) ) if ( most == ( - 1 ) ) : return [ ] for k in range ( len ( best ) ) : best_keys [ k ] = ( best_keys [ k ] , best [ k ] ) best_keys . sort ( key = ( lambda x : len ( x [ 1 ] ) ) ) return best_keys
return a list of tuples where s is the largest subset of elements that appear in pairs of sets given by sets and l is a list of tuples giving the indices of the pairs of sets in which those elements appeared .