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

seofangfa python笔记评论2,131阅读模式

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

文章末尾固定信息

weinxin
我的微信
我的微信
微信扫一扫
 
seofangfa
  • 本文由 seofangfa 发表于 2016年12月9日19:17:47
  • 转载请务必保留本文链接:https://wp.fangfa.me/python-note/python-vlookup.html
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
确定

拖动滑块以完成验证