def ranks_from_scores(scores, rank_gap=1e-15):
 prev_score = None
 rank = 0
 for (i, (key, score)) in enumerate(scores):
  try:
   if (abs((score - prev_score)) > rank_gap):
    rank = i
  except TypeError:
   pass
  (yield (key, rank))
  prev_score = score

def ranks_from_scores ( scores , rank_gap = 1e-15 ) : prev_score = None rank = 0 for ( i , ( key , score ) ) in enumerate ( scores ) : try : if ( abs ( ( score - prev_score ) ) > rank_gap ) : rank = i except TypeError : pass ( yield ( key , rank ) ) prev_score = score
given a sequence of tuples .