From a8f6a99bb3d3dba85705ed7df93145c28168d659 Mon Sep 17 00:00:00 2001 From: Hui Lan Date: Fri, 1 Nov 2019 20:51:19 +0800 Subject: englishpal: first commit --- app/WordFreq.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 app/WordFreq.py (limited to 'app/WordFreq.py') diff --git a/app/WordFreq.py b/app/WordFreq.py new file mode 100644 index 0000000..18f2c49 --- /dev/null +++ b/app/WordFreq.py @@ -0,0 +1,20 @@ +from wordfreqCMD import remove_punctuation, freq, sort_in_descending_order +import string + +class WordFreq: + def __init__(self, s): + self.s = remove_punctuation(s) + + def get_freq(self): + lst = [] + for t in freq(self.s): + word = t[0] + if len(word) > 0 and word[0] in string.ascii_letters: + lst.append(t) + return sort_in_descending_order(lst) + + +if __name__ == '__main__': + f = WordFreq('BANANA; Banana, apple ORANGE Banana banana.') + print(f.get_freq()) + -- cgit v1.2.1