python加载自定义词典实例
作者:佳佳holiday 时间:2021-07-15 14:53:55
如下所示:
#加载词典
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
来源:https://blog.csdn.net/u013783249/article/details/80683863
标签:python,加载,自定义,词典
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
拖拽翻页(ThrowPage)详解 cool
2009-12-02 09:54:00
![](https://img.aspxhome.com/file/UploadPic/200912/2/01-46s.jpg)
python使用RNN实现文本分类
2023-10-17 14:07:18
![](https://img.aspxhome.com/file/2023/1/96461_0s.jpg)
python实现音乐播放和下载小程序功能
2023-07-03 17:59:03
![](https://img.aspxhome.com/file/2023/5/105855_0s.jpg)
讲解MySQL数据库字符集出错的解决方法
2008-12-02 14:32:00
关于web标准的思考
2008-10-05 10:07:00
浅析Banner构成与创意设计
2009-11-28 16:25:00
![](https://img.aspxhome.com/file/UploadPic/200911/28/originality-design-55s.jpg)
关于网站导航设计的探讨
2008-02-28 13:20:00
![](https://img.aspxhome.com/file/UploadPic/up/2008022813384765.gif)
Python基本语法经典教程
2021-08-25 18:16:51
![](https://img.aspxhome.com/file/2023/2/113162_0s.png)
如何建设一个多语言版的ASP网站?
2009-11-26 20:36:00
thinkphp3查询mssql数据库乱码解决方法分享
2023-11-15 00:52:22
Python获取时间的操作示例详解
2023-05-21 07:54:56
![](https://img.aspxhome.com/file/2023/7/109637_0s.png)
sqlserver中如何查询出连续日期记录的代码
2011-09-30 11:16:56
php集成环境xampp中apache无法启动问题解决方案
2023-07-17 22:44:52
![](https://img.aspxhome.com/file/2023/8/55478_0s.png)
Python如何读取csv文件时添加表头/列名
2023-04-27 15:43:37
JavaScript正则表达式的简单应用:高亮显示
2008-07-20 12:46:00
Python实现批量自动整理文件
2023-05-10 21:58:12
![](https://img.aspxhome.com/file/2023/7/110577_0s.png)
python正则表达式re.group()用法
2021-08-17 03:31:03
Python中int()函数的用法浅析
2022-08-18 09:45:12
利用Pycharm将python文件打包为exe文件的超详细教程(附带设置文件图标)
2021-12-06 18:06:24
![](https://img.aspxhome.com/file/2023/8/93888_0s.png)
SQL Server服务器内存升级后的烦恼
2008-12-22 10:55:00