Skip to content

Commit

Permalink
use itemgetter for sorting, and remove unneccessary max after sort
Browse files Browse the repository at this point in the history
  • Loading branch information
boidolr committed Dec 6, 2015
1 parent 543333b commit bef83e5
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions wordcloud/wordcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,12 @@ def generate_from_frequencies(self, frequencies):
"""
# 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]
# 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[i] = word, freq / max_frequency
frequencies = [ (word, freq / max_frequency) for word, freq in frequencies ]

self.words_ = frequencies

Expand Down

0 comments on commit bef83e5

Please sign in to comment.