2020-06-22

#coding=utf-8

one, two, oF, tF = {}, {}, {}, {} #one, 字符串: 数字 都是唯一数据… oF 相反

list1, list2 = [], [] # 循环的数据 可以重复定义的.

oneStr, oneInt, twoStr, twoInt = [], [], [], []
obj = {} #最终输出数据

fo = open("./1.txt", “r”)
fo2 = open("./2.txt", “r”)

def outDict(str, dict, dF): #定义函数. 将str转换成字典
dict[str.partition("=")[0]] = str.partition("=")[2]
dF[“key” + str.partition("=")[2]] = str.partition("=")[0] # + key 区分 字典中key值是 是数字的问题. 在最终输出时 以去除
# print(str, str.partition("=")[2])
# print(dict)

for line in fo.readlines():
outDict(line.strip(), one, oF)

for line in fo2.readlines():
outDict(line.strip(), two, tF)

oneStr = one.keys() #key值 数组

oneInt = one.values() #value值 数组

oneInt = map(lambda x: ‘key’ + x, one.values()) #value值 数组
twoStr = two.keys() #key值 数组

twoInt = two.values() #value值 数组

twoInt = map(lambda x: ‘key’ + x, two.values()) #value值 数组
print oF
print tF

print one

print two

已one数据为主循环数据

for item in oneStr:
if item in twoStr:
if one[item] != two[item]:
obj[item] = one[item] + " " + two[item]

for item in oneInt:
if item in twoInt:
if oF[item] != tF[item]:
obj[oF[item] + " " + tF[item]] = item

for item in obj:
obj[item] = obj[item].replace(“key”, “”) # + key 区分 字典中key值是 是数字的问题. 在最终输出时 以去除

print obj

with open("./out.txt", ‘w’) as file_obj:
for l in obj:
file_obj.write(l + " " + obj[l] + “\n”)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值