summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHui Lan <lanhui@zjnu.edu.cn>2019-12-26 18:20:35 +0800
committerHui Lan <lanhui@zjnu.edu.cn>2019-12-26 18:20:35 +0800
commit6db297407cad6a49ae977498a4ea4749dc98059f (patch)
tree9f61c433ddbacfd0e41c24c6a99f88795a5bdb17
parent449269fa5262d9c4d3eaa2cea457f78471a14234 (diff)
merge_edges.py: save memory by removing the dictionary variable duniq
The purpose of duniq is to avoid duplicated edge lines. Now, just make sure we don't insert the same tuple. -Hui
-rw-r--r--Code/merge_edges.py7
1 files changed, 2 insertions, 5 deletions
diff --git a/Code/merge_edges.py b/Code/merge_edges.py
index 936faf5..a8bd3b9 100644
--- a/Code/merge_edges.py
+++ b/Code/merge_edges.py
@@ -124,17 +124,14 @@ def make_new_edge(lst_tuple):
##main
-
d = {}
-duniq = {}
for fname in sorted(glob.glob(os.path.join(EDGE_POOL_DIR, '*.*'))):
print('[merge_edges.py]: including %s.' % (fname))
f = open(fname)
for line in f:
line = line.strip()
- if len(line.split('\t')) == 10 and not line in duniq:
- duniq[line] = 1
+ if len(line.split('\t')) == 10:
lst = line.split('\t')
target = lst[0]
tf = lst[1]
@@ -152,7 +149,7 @@ for fname in sorted(glob.glob(os.path.join(EDGE_POOL_DIR, '*.*'))):
if not key in d:
d[key] = [t]
- else:
+ elif not t in d[key]: # make sure the tuple to be added to d[key] (a list) does not alreay exist.
d[key].append(t)
f.close()