From 643e0c4eee7aade262db1f2cab4db9a6f797560c Mon Sep 17 00:00:00 2001 From: vicky-ZhuWenqi <72480049+vicky-ZhuWenqi@users.noreply.github.com> Date: Mon, 31 May 2021 08:48:03 +0800 Subject: [PATCH] Update pickle_idea.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在生词簿每个单词后面,加上两个按钮,熟悉与不熟悉。如果点熟悉,就将生词簿中该单词后面记录的添加次数减一,直至减为0,就将该单词从生词簿中移除;如果点不熟悉,就将生词簿中该单词后面记录的添加次数加一。 --- app/pickle_idea.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/pickle_idea.py b/app/pickle_idea.py index 2061d7c..45bd19a 100644 --- a/app/pickle_idea.py +++ b/app/pickle_idea.py @@ -7,6 +7,7 @@ # Task: incorporate the functions into wordfreqCMD.py such that it will also show cumulative frequency. import pickle +from datetime import datetime def lst2dict(lst, d): @@ -53,7 +54,22 @@ def save_frequency_to_pickle(d, pickle_fname): pickle.dump(d2, f) f.close() +def unfamiliar(path,word): + f = open(path,"rb") + dic = pickle.load(f) + dic[word] += [datetime.now().strftime('%Y%m%d%H%M')] + fp = open(path,"wb") + pickle.dump(dic,fp) +def familiar(path,word): + f = open(path,"rb") + dic = pickle.load(f) + if len(dic[word])>1: + del dic[word][0] + else: + dic.pop(word) + fp = open(path,"wb") + pickle.dump(dic,fp) if __name__ == '__main__':