欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python加載自定義詞典實例

 更新時間:2019年12月06日 09:05:09   作者:佳佳holiday  
今天小編就為大家分享一篇python加載自定義詞典實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

如下所示:

#加載詞典
def load_dict_from_file(filepath):
  _dict = {}
  try:
    with io.open(filepath, 'r',encoding='utf-8') as dict_file:
      for line in dict_file:
        (key, value) = line.strip().split(' ') #將原本用空格分開的鍵和值用冒號分開來,存放在字典中
        _dict[key] = value
  except IOError as ioerr:
    print("文件 %s 不存在" % (filepath))
  return _dict
#加載停用詞詞典
def stopwordslist(filepath):
  stopwords = {}
  fstop = io.open(filepath, 'r',encoding='utf-8')
  for line in fstop:
    stopwords[line.strip()]=line.strip()
  fstop.close()
  return stopwords

以上這篇python加載自定義詞典實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論