code: def BP(candidate, references):
      
      c = len(candidate)
      ref_lens = (len(reference) for reference in references)
      r = min(ref_lens, key=lambda ref_len: (abs(ref_len - c), ref_len))
  
      if c > r:
          return 1
      else:
          return math.exp(1 - r / c)
docs: calculate brevity penalty