code: def term_rank(self, items, print_output=True):
  
          
  
          if items == 'stems':
              v = self.stems
          elif items == 'tokens':
              v = self.tokens
          elif items == 'bigrams':
              v = self.bigrams
          else:
              raise ValueError("Items must be either \'tokens\' , \'bigrams\' or \'stems\'.")
  
          agg = itertools.chain(*v)
          counts = collections.Counter(agg)
  
          v_unique = list(map(lambda x: set(x), v))
          agg_d = itertools.chain(*v_unique)
          counts_d = collections.Counter(agg_d)
  
          unique_tokens = set(itertools.chain(*v))
  
          def tf_idf_compute(t):
              return (1 + np.log(counts[t]))*np.log(self.N/counts_d[t])
  
          unsorted_df = [counts[t] for t in unique_tokens]
          unsorted_tf_idf = [tf_idf_compute(t) for t in unique_tokens]
  
          self.df_ranking = sorted(zip(unique_tokens, unsorted_df),
                                   key=lambda x: x[1], reverse=True)
          self.tfidf_ranking = sorted(zip(unique_tokens, unsorted_tf_idf),
                                      key=lambda x: x[1], reverse=True)
  
          if print_output:
              with codecs.open('df_ranking.csv', 'w', 'utf-8') as f:
                      for p in self.df_ranking:
                          f.write("%s,%d\n" % (p[0], p[1]))
              with codecs.open('tfidf_ranking.csv', 'w', 'utf-8') as f:
                      for p in self.tfidf_ranking:
                          f.write("%s,%f\n" % (p[0], p[1]))
docs: Calculate corpus-level df and tf-idf scores on either tokens (items =
          "tokens") bigrams (items = 'bigrams') or stems (items = "stems"). Print to file if
          print_output = True.