class WordCloudOp:

    def run(self, data):
        terms = { }
        results = [ ]
        try:
            for corpus in data:
                tokens = corpus.tokenized_contents
                for token in tokens:
                    if token in terms:
                        terms[token]+=1
                    else:
                        terms[token]=1
            for term in terms:
                results.append({ "term" : term, "frequency" : terms[term]})
            return results
        except LookupError:
            raise TransactionException('NLTK \'Punkt\' Model not installed.', 500)
        except TypeError:
            raise TransactionException('Corpus contents does not exist.')


class WordCloudOp:

    def run(self, data):
        terms = { }
        results = [ ]
        try:
            for corpus in data:
                tokens = corpus.tokenized_contents
                for token in tokens:
                    if token in terms:
                        terms[token]+=1
                    else:
                        terms[token]=1
            for term in terms:
                results.append({ "term" : term, "frequency" : terms[term]})

            #sort results by term frequency
            results.sort(key=lambda results: results['frequency'], reverse=False)
            
            return results
        except LookupError:
            raise TransactionException('NLTK \'Punkt\' Model not installed.', 500)
        except TypeError:
            raise TransactionException('Corpus contents does not exist.')


Sort term frequency results by frequency
Sort term frequency results by frequency

  class WordCloudOp:
  
      def run(self, data):
          terms = { }
          results = [ ]
          try:
              for corpus in data:
                  tokens = corpus.tokenized_contents
                  for token in tokens:
                      if token in terms:
                          terms[token]+=1
                      else:
                          terms[token]=1
              for term in terms:
                  results.append({ "term" : term, "frequency" : terms[term]})
+ 
+             #sort results by term frequency
+             results.sort(key=lambda results: results['frequency'], reverse=False)
+             
              return results
          except LookupError:
              raise TransactionException('NLTK \'Punkt\' Model not installed.', 500)
          except TypeError:
              raise TransactionException('Corpus contents does not exist.')
  
  
Sort term frequency results by frequency
## Code Before:
class WordCloudOp:

    def run(self, data):
        terms = { }
        results = [ ]
        try:
            for corpus in data:
                tokens = corpus.tokenized_contents
                for token in tokens:
                    if token in terms:
                        terms[token]+=1
                    else:
                        terms[token]=1
            for term in terms:
                results.append({ "term" : term, "frequency" : terms[term]})
            return results
        except LookupError:
            raise TransactionException('NLTK \'Punkt\' Model not installed.', 500)
        except TypeError:
            raise TransactionException('Corpus contents does not exist.')


## Instruction:
Sort term frequency results by frequency
## Code After:
class WordCloudOp:

    def run(self, data):
        terms = { }
        results = [ ]
        try:
            for corpus in data:
                tokens = corpus.tokenized_contents
                for token in tokens:
                    if token in terms:
                        terms[token]+=1
                    else:
                        terms[token]=1
            for term in terms:
                results.append({ "term" : term, "frequency" : terms[term]})

            #sort results by term frequency
            results.sort(key=lambda results: results['frequency'], reverse=False)
            
            return results
        except LookupError:
            raise TransactionException('NLTK \'Punkt\' Model not installed.', 500)
        except TypeError:
            raise TransactionException('Corpus contents does not exist.')

