Skip to content

Commit 2ba08e7

Browse files
authored
Merge pull request textstat#57 from catethos/master
Using Counter to obtain the Readability Consensus
2 parents 4f03c17 + 63f63d3 commit 2ba08e7

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

textstat/textstat.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import re
99
import math
1010
import operator
11+
from collections import Counter
1112

1213
import pkg_resources
1314
import repoze.lru
@@ -332,13 +333,12 @@ def text_standard(self, text, float_output=None):
332333
grade.append(int(upper))
333334

334335
# Finding the Readability Consensus based upon all the above tests
335-
d = dict([(x, grade.count(x)) for x in grade])
336-
sorted_x = sorted(d.items(), key=operator.itemgetter(1))
337-
final_grade = str((sorted_x)[len(sorted_x)-1])
338-
score = final_grade.split(',')[0].strip('(')
339-
336+
d = Counter(grade)
337+
final_grade = d.most_common(1)
338+
score = final_grade[0][0]
339+
340340
if float_output:
341-
return score
341+
return float(score)
342342
else:
343343
return "{}th and {}th grade".format(
344344
str(int(score)-1), str(int(score))

0 commit comments

Comments
 (0)