- A+
所属分类:python笔记
python实现vlookup功能:找出列表中不同的项
直接上代码,留着备用。
#!/usr/local/bin/pyhton # -*- coding: utf-8 -*- #从all.txt里把bad.txt里的行挑出来,再存为good.txt,起到了vlookup的作用 a_dict = {} b_dict = {} a_i = 1 for a_line in open('all.txt'): a_dict['%s'%(a_line.strip())] = a_i a_i += 1 #print a_dict b_i = 1 for b_line in open('bad.txt'): b_dict['%s'%(b_line.strip())] = a_i b_i += 1 #print b_dict f = open("good.txt","w") for a1 in a_dict.keys(): if a1 in b_dict.keys(): pass else: print >>f,a1