From 097f83023866d625a38c891a46ce3a70d73d7f63 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 31 Aug 2021 06:56:15 +0200 Subject: [PATCH] Avoid mutable default arguments (#4691) --- graphs/eulerian_path_and_circuit_for_undirected_graph.py | 4 ++-- graphs/frequent_pattern_graph_miner.py | 4 ++-- maths/radix2_fft.py | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/graphs/eulerian_path_and_circuit_for_undirected_graph.py b/graphs/eulerian_path_and_circuit_for_undirected_graph.py index 7850933b0..fa4f73abd 100644 --- a/graphs/eulerian_path_and_circuit_for_undirected_graph.py +++ b/graphs/eulerian_path_and_circuit_for_undirected_graph.py @@ -6,8 +6,8 @@ # using dfs for finding eulerian path traversal -def dfs(u, graph, visited_edge, path=[]): - path = path + [u] +def dfs(u, graph, visited_edge, path=None): + path = (path or []) + [u] for v in graph[u]: if visited_edge[u][v] is False: visited_edge[u][v], visited_edge[v][u] = True, True diff --git a/graphs/frequent_pattern_graph_miner.py b/graphs/frequent_pattern_graph_miner.py index 8f344b7bd..548ce3c54 100644 --- a/graphs/frequent_pattern_graph_miner.py +++ b/graphs/frequent_pattern_graph_miner.py @@ -168,11 +168,11 @@ def construct_graph(cluster, nodes): return graph -def myDFS(graph, start, end, path=[]): +def myDFS(graph, start, end, path=None): """ find different DFS walk from given node to Header node """ - path = path + [start] + path = (path or []) + [start] if start == end: paths.append(path) for node in graph[start]: diff --git a/maths/radix2_fft.py b/maths/radix2_fft.py index de87071e5..9fc9f843e 100644 --- a/maths/radix2_fft.py +++ b/maths/radix2_fft.py @@ -49,10 +49,10 @@ class FFT: 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) """ - def __init__(self, polyA=[0], polyB=[0]): + def __init__(self, polyA=None, polyB=None): # Input as list - self.polyA = list(polyA)[:] - self.polyB = list(polyB)[:] + self.polyA = list(polyA or [0])[:] + self.polyB = list(polyB or [0])[:] # Remove leading zero coefficients while self.polyA[-1] == 0: