From 70f2ed0d933f7316a9d00adf33b630c98a3f183d Mon Sep 17 00:00:00 2001 From: coded9 Date: Sun, 11 Jun 2017 06:51:00 +0000 Subject: [PATCH 1/2] Done --- count_word.py | 13 +++++++++++++ count_word.pyc | Bin 0 -> 567 bytes tests/__init__.pyc | Bin 0 -> 158 bytes tests/test_countWord.pyc | Bin 0 -> 1216 bytes 4 files changed, 13 insertions(+) create mode 100644 count_word.pyc create mode 100644 tests/__init__.pyc create mode 100644 tests/test_countWord.pyc diff --git a/count_word.py b/count_word.py index e69de29..a920043 100644 --- a/count_word.py +++ b/count_word.py @@ -0,0 +1,13 @@ + +def countWord(filepath,testWord): + fp = open(filepath,"r") + wordDict = {} + for line in fp.readlines(): + print line + for word in line.split(" "): + if word in wordDict: + wordDict[word] += 1 + else: + wordDict[word] = 1 + return wordDict[testWord] +#countWord("files/testfile.txt","Lorem") diff --git a/count_word.pyc b/count_word.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ee26d4cc2bbffac6219b5089f5c3359e46c0490e GIT binary patch literal 567 zcmb_YO;5r=5PjPM!4F~ri3vC3sTb_Y7!xoglIV$p9Ee6^uv?^1+QKdolXAiz>)k)# zn?m9ru<5>;_hveMv+hsru=Cx146uI`W0%L&2paeTo|q^MJcmjkP}!ebMw1gPz`&-h zgN=g-*tl3fBX=;R2=re1*p!f$aCg7%N}M{-4z`LVADc3AzAk1JEZ-y{<*%CB#g*G$ zbiib%3K=fWF%+uM9C#%f=v(oo71hTv!1OBWgbF1h>Eh3CbH-S?+)xY3tH%LTi1)y!_KMi zbR+AS9p)|sL-&=o`>spjkYOxb@Z>An;IQ@%Y^gD_v2VV#Y2`4Te%7=yc8zDu+j_2n zX&T7QKPPErWbEdJ4}IkVVKy8tW^N%j4}}FSSry%xJZX(IZPg7*w|yGIN=}&f*hQDR zmQkj2nLm#(HdkhzW}P7_Om5_4zOa{CO~AJNq-v?`-jfa(7reg u`Fgnv+N#oWS}_b{IVH&*GOi`A{;q>A!maakjE=h6yx^HIOnfY!`2PSej1%1e literal 0 HcmV?d00001 From f9fe90d12732d70ca6c593ef4865b60800dba61a Mon Sep 17 00:00:00 2001 From: coded9 Date: Sun, 11 Jun 2017 06:58:41 +0000 Subject: [PATCH 2/2] Done --- count_word.py | 21 ++++++++++++--------- count_word.pyc | Bin 567 -> 606 bytes 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/count_word.py b/count_word.py index a920043..4327f48 100644 --- a/count_word.py +++ b/count_word.py @@ -1,13 +1,16 @@ def countWord(filepath,testWord): - fp = open(filepath,"r") + #fp = open(filepath,"r") wordDict = {} - for line in fp.readlines(): - print line - for word in line.split(" "): - if word in wordDict: - wordDict[word] += 1 - else: - wordDict[word] = 1 + #for line in fp.readlines(): + with open(filepath,"r") as file: + for line in file: + print line + for word in line.split(" "): + if word in wordDict: + wordDict[word] += 1 + else: + wordDict[word] = 1 + #print wordDict[testWord] return wordDict[testWord] -#countWord("files/testfile.txt","Lorem") +countWord("files/testfile.txt","Lorem") diff --git a/count_word.pyc b/count_word.pyc index ee26d4cc2bbffac6219b5089f5c3359e46c0490e..b890db81794e95c67c66c0b6c10abc17fe6f4530 100644 GIT binary patch delta 326 zcmXYr%}T>S6ot>sBte65QGZYux-Bj&xDiShg%<2W3n~~DL?MX~t;Qw;&0<0qx|h<2 zapT^%@B!S4d(X5EbMAa|&)m89-T89H>L>75zgw3P{+Hs}riv|w7cP)TUO%!*j?c8f}(Jcm)}UiVQsFb)oTW&7B|{rqP^uYt;i z;g)#tkl$F~m5nyp^+2_TO%Uc;dkKd-2t&?!a$)4;V>_@TX**o@oIFi_ch?rkqb!fR zX{2YyT{=jn`@%G(Cu<@Qu2>gKVnuGqqQ