def get_num_cat(sample_by_cat, samples_in_otus):
 num_cat = defaultdict(int)
 for (cat, samples) in sample_by_cat.items():
  num_samples = len((set(samples_in_otus) & set(samples)))
  num_cat[cat[0]] += ((num_samples * (num_samples - 1)) / 2)
 return num_cat

def get_num_cat ( sample_by_cat , samples_in_otus ) : num_cat = defaultdict ( int ) for ( cat , samples ) in sample_by_cat . items ( ) : num_samples = len ( ( set ( samples_in_otus ) & set ( samples ) ) ) num_cat [ cat [ 0 ] ] += ( ( num_samples * ( num_samples - 1 ) ) / 2 ) return num_cat
builds a dictionary of numbers of samples keyed by metadata value .