Commit bef83e5a authored by Raphael Boidol's avatar Raphael Boidol
Browse files

use itemgetter for sorting, and remove unneccessary max after sort

parent 543333be
...@@ -227,13 +227,12 @@ class WordCloud(object): ...@@ -227,13 +227,12 @@ class WordCloud(object):
""" """
# make sure frequencies are sorted and normalized # make sure frequencies are sorted and normalized
frequencies = sorted(frequencies, key=lambda x: x[1], reverse=True) frequencies = sorted(frequencies, key=item1, reverse=True)
frequencies = frequencies[:self.max_words] frequencies = frequencies[:self.max_words]
# largest entry will be 1 # largest entry will be 1
max_frequency = float(np.max([freq for word, freq in frequencies])) max_frequency = float(frequencies[0][1])
for i, (word, freq) in enumerate(frequencies): frequencies = [ (word, freq / max_frequency) for word, freq in frequencies ]
frequencies[i] = word, freq / max_frequency
self.words_ = frequencies self.words_ = frequencies
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment