Skip to content

Commit b2bc779

Browse files
author
Hamid Gasmi
committed
#170 __repr__ is used to make the code cleaner
1 parent a55025b commit b2bc779

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

06-dynamic-programming-applications-in-machine-learning-and-genomics/1-sequence-alignment-1/longest_path_dag_bfs.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ def longest_path_bfs(self, source, sink):
101101
self.longest_path_len = max_distance[sink_vertex].dist
102102
self.longest_path = self.longest_path_backtrack(sink_vertex, max_distance)
103103

104-
def longest_path_to_str(self):
105-
106-
return '->'.join(self.longest_path)
104+
def __repr__(self):
107105

106+
return f"{self.longest_path_len} \n" + '->'.join(self.longest_path)
107+
108108
if __name__ == "__main__":
109109

110110
source = int(sys.stdin.readline().strip())
@@ -113,6 +113,6 @@ def longest_path_to_str(self):
113113

114114
dag = Directed_Acyclic_Graph(source, sink, edges)
115115
dag.longest_path_bfs(source, sink)
116+
117+
print(dag)
116118

117-
print(dag.longest_path_len)
118-
print(dag.longest_path_to_str())

06-dynamic-programming-applications-in-machine-learning-and-genomics/1-sequence-alignment-1/longest_path_dag_topological_order.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ def compute_longest_path(self):
119119
self.longest_path_len = max_distance[sink_vertex].dist
120120
self.longest_path = self.longest_path_backtrack(sink_vertex, max_distance)
121121

122-
def longest_path_to_str(self):
122+
def __repr__(self):
123123

124-
return '->'.join(self.longest_path)
124+
return f"{self.longest_path_len} \n" + '->'.join(self.longest_path)
125125

126126
if __name__ == "__main__":
127127

@@ -131,6 +131,5 @@ def longest_path_to_str(self):
131131

132132
dag = Directed_Acyclic_Graph(source, sink, edges)
133133
dag.compute_longest_path()
134-
135-
print(dag.longest_path_len)
136-
print(dag.longest_path_to_str())
134+
135+
print(dag)

0 commit comments

Comments
 (0)