我有这段代码:
if pair.direction == "F1R2" or pair.direction == "R2F1":
key = float(str(pair.r1.reference_id)+str(orient[pair.direction])+"."+str(pair.r1.pos))
value = float(str(pair.r2.reference_id)+str(orient[pair.direction])+"."+str(pair.r2.pos+pair.frside))
elif pair.direction == "F1F2" or pair.direction == "F2F1":
key = float(str(pair.r1.reference_id)+str(orient[pair.direction])+"."+str(pair.r1.pos))
value = float(str(pair.r2.reference_id)+str(orient[pair.direction])+"."+str(pair.r2.pos))
elif pair.direction == "R1R2" or pair.direction == "R2R1":
key = float(str(pair.r1.reference_id)+str(orient[pair.direction])+"."+str(pair.r1.pos+pair.frside))
value = float(str(pair.r2.reference_id)+str(orient[pair.direction])+"."+str(pair.r2.pos+pair.frside))
else: #F2R1 or R1F2
key = float(str(pair.r1.reference_id)+str(orient[pair.direction])+"."+str(pair.r1.pos+pair.frside))
value = float(str(pair.r2.reference_id)+str(orient[pair.direction])+"."+str(pair.r2.pos))
if pair.r1.reference_id in dupes:
if key in dupes[pair.r1.reference_id]:
#duplicate!!!
outputs["duplicates"].put([attr1,attr2])
continue
else:
dupes[pair.r1.reference_id][key] = value
else: #not a dup
dupes[pair.r1.reference_id] = {key: value}
在字典dupes
中,它可能包含~100M密钥。您是否知道搜索或关联key
和value
变量的更快捷方式? key
和value
个变量都是floats
。