python实现vlookup功能:找出列表中不同的项

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

  • 版权声明:除非注明,本博客均为北京SEO方法的原创文章,转载或引用请以超链接形式标明本文地址,否则会在SEO圈内公开此种不尊重版权的行为,谢谢合作!本文地址:http://seofangfa.com/python-note/python-vlookup.html
    本文信息:于1个月前,由方法SEO发表,共 397字。

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: