Skip to content

Commit b3447e0

Browse files
committed
Avoid mutable default arguments
1 parent 3acca3d commit b3447e0

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

Diff for: graphs/eulerian_path_and_circuit_for_undirected_graph.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77

88
# using dfs for finding eulerian path traversal
9-
def dfs(u, graph, visited_edge, path=[]):
10-
path = path + [u]
9+
def dfs(u, graph, visited_edge, path=None):
10+
path = (path or []) + [u]
1111
for v in graph[u]:
1212
if visited_edge[u][v] is False:
1313
visited_edge[u][v], visited_edge[v][u] = True, True

Diff for: graphs/frequent_pattern_graph_miner.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,11 @@ def construct_graph(cluster, nodes):
168168
return graph
169169

170170

171-
def myDFS(graph, start, end, path=[]):
171+
def myDFS(graph, start, end, path=None):
172172
"""
173173
find different DFS walk from given node to Header node
174174
"""
175-
path = path + [start]
175+
path = (path or []) + [start]
176176
if start == end:
177177
paths.append(path)
178178
for node in graph[start]:

Diff for: maths/radix2_fft.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ class FFT:
4949
A*B = 0*x^(-0+0j) + 1*x^(2+0j) + 2*x^(3+0j) + 3*x^(8+0j) + 4*x^(6+0j) + 5*x^(8+0j)
5050
"""
5151

52-
def __init__(self, polyA=[0], polyB=[0]):
52+
def __init__(self, polyA=None, polyB=None):
5353
# Input as list
54-
self.polyA = list(polyA)[:]
55-
self.polyB = list(polyB)[:]
54+
self.polyA = list(polyA or [])[:]
55+
self.polyB = list(polyB or [])[:]
5656

5757
# Remove leading zero coefficients
5858
while self.polyA[-1] == 0:

0 commit comments

Comments
 (0)