#create a mapping of old vars to new vars.
with open('definitions') as f:
d = dict( [x.split() for x in f] )
def my_replace(match):
#if the match is in the dictionary, replace it, otherwise, return the match unchanged.
return d.get( match.group(), match.group() )
with open('inquiry') as f:
for line in f:
print re.sub( r'\w+', my_replace, line )
如果每一部分都是一个单独的单词,
re.sub
绝对是这里的方法:从概念上讲
我可能会首先建立一个编码映射->英语(在内存或o
然后,对于地图中的每一个编码,扫描你的文件并用对应的英语代码替换。在
这将为您提供键、值对的列表
我不知道你想对结果做什么,尽管,你需要更明确
相关问题 更多 >
编程相关推荐