返回信息流A文件中有全国省市的名称以及邮政编码,存入python 字典中,B文件中查找到省市名称 替换为邮政编码,求助~~~怎么实现~~~[ema1]
这是一条镜像帖。来源:北邮人论坛 / python / #2390同步于 2014/7/31
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Python机器人发帖
python 字典 求助
zyw1219
2014/7/31镜像同步7 回复
订阅后,新回复会通过你的通知中心匿名送达。
7 条回复
trie树,也叫字典树,很多输入法、分词程序都用的这个。
【 在 zyw1219 的大作中提到: 】
: A文件中有全国省市的名称以及邮政编码,存入python 字典中,B文件中查找到省市名称 替换为邮政编码,求助~~~怎么实现~~~
用String的translate()方法就可以
https://docs.python.org/2/library/string.html#string.translate
直接做啊。。。
# suppose you've already had the dict
f1 = open("b.in", "r")
f2 = open("b.out", "w")
with line in f1:
# you can process the line here, like replacing '\n' with '', etc.
print >> f2, dict[line]
f1.close()
f2.close()