python映射关系
来源:互联网 发布:iphone导入照片软件 编辑:程序博客网 时间:2024/06/17 21:05
有关系A和B的文件,其中A-->B,B有可能也是A的成员,寻找一个tree,如果B已经到达最顶层,那么A-->B为正确的映射关系,如果出现循环则记录这些错误,和key的最终指向
#-*-coding:UTF-8-*-#!/usr/bin/env python__author__ = 'chao.zhang.sh'import threadingclass Mapping(): def __init__(self): self.Mapping={} self.LastMerge={} self.keys=None def Search(self): try: DataFile=open('mapping.csv','r') DataWrite=open('Result/mappingResult.csv','w') DataWriteCircle=open('Result/mappingResultWrong.csv','a') A=[] B=[] DataFile.next() for temp in DataFile: data=temp.decode("utf-8").strip().split("\t") self.Mapping[data[1]]=data[2] A.append(data[1]) B.append(data[2]) self.keys=self.Mapping.keys() for temp in (set(B).difference(set(A)))://求第二列和第一列的差集 self.Mapping[temp]=int(-1)//将差集全部置-1 print len(self.Mapping) i=0 for key in self.keys: i+=1 j=0 Keys=[key] while True: if int(self.Mapping[Keys[-1]])==int(-1)://遇到-1,证明已经找到树顶部 DataWrite.write("\t".join([key,Keys[-1]]).encode("utf-8")+"\n") break//跳出while循环 else: if self.Mapping[Keys[-1]] in Keys://遇到新的key值出现在keys列表中,证明出现了循环,记录错误数据 DataWriteCircle.write("\t".join(Keys).encode("utf-8")+"\n") break Keys.append(self.Mapping[Keys[-1]]) print "key:%s newKey:%s"%(key,Keys[-1]) print i except Exception as err: print err finally: DataFile.close() DataWrite.flush() DataWrite.close() DataWriteCircle.flush() DataWriteCircle.close() if "__main__"==__name__: A=Mapping() A.Search()
0 0
- python映射关系
- 关系映射
- hibernate映射关系一对一映射
- 对象关系映射
- hibernate3 关系映射 使用说明
- 映射继承关系
- 关系/对象映射
- 对象关系映射
- 关联关系映射
- Hibernate3 关系映射使用说明
- Rails 中的映射关系:
- 关联关系映射
- ER-关系映射方法
- 实体关系映射
- 关联关系映射
- Hibernate关系映射
- Hibernate 继承关系映射
- 1.4 对象关系映射
- 牟家和:2015大学生创业谈
- android怎样调用@hide和internal API
- Storm计算结果是如何存放的
- Python爬虫学习開篇
- log4j日志动态配置(log4j.properties)
- python映射关系
- Python中的copy()方法为“浅复制”
- 暑假要看的东西
- 【leetcode】Repeated DNA Sequences
- 【Windows】win7 凭据的永久性问题
- openssl 转换证书
- Swift面向对象之枚举
- UML类图几种关系
- hibernate的查询缓存