文件1为key,文件2为key-value(两列),从文件1读取key,然后从文件2中找出value后叠加
-
import re$
-
import urllib2$
-
def itercolumn23(filename, splitregex = '\t'):$
-
with open(filename, 'rt') as handle:$
-
for ln in handle:$
-
items = re.split(splitregex, ln)$
-
yield items[0], items[1]$//返回文件第一列和第二列
-
$
-
............$
-
if __name__ == '__main__':.$
-
a = [str(l.split()[0]) for l in open("nometa")]$ //把只有一列的txt文件转化成str类型的list
-
for x, y in itercolumn23("有两列的文件",splitregex = '\s+'):$
-
//x为第一列,y为第二列
-
if x in a:$
-
print y$
阅读(3903) | 评论(0) | 转发(0) |