diff --git a/algorithms/automata/dfa.py b/algorithms/automata/dfa.py index 36211c7e8..34f73a4b4 100644 --- a/algorithms/automata/dfa.py +++ b/algorithms/automata/dfa.py @@ -3,16 +3,15 @@ def DFA(transitions, start, final, string): num = len(string) num_final = len(final) cur = start - - for i in range (num): - - if transitions[cur][string[i]] == None: + + for i in range(num): + + if transitions[cur][string[i]] is None: return False else: cur = transitions[cur][string[i]] - for i in range (num_final): + for i in range(num_final): if cur == final[i]: return True return False - diff --git a/algorithms/graph/tarjan.py b/algorithms/graph/tarjan.py index a2f44e58d..399a39d6d 100644 --- a/algorithms/graph/tarjan.py +++ b/algorithms/graph/tarjan.py @@ -5,6 +5,7 @@ """ from algorithms.graph.graph import DirectedGraph + class Tarjan(object): def __init__(self, dict_graph): self.graph = DirectedGraph(dict_graph) @@ -18,7 +19,7 @@ def __init__(self, dict_graph): self.sccs = [] for v in self.graph.nodes: - if v.index == None: + if v.index is None: self.strongconnect(v, self.sccs) def strongconnect(self, v, sccs): @@ -31,7 +32,7 @@ def strongconnect(self, v, sccs): # Consider successors of v for w in self.graph.adjmt[v]: - if w.index == None: + if w.index is None: # Successor w has not yet been visited; recurse on it self.strongconnect(w, sccs) v.lowlink = min(v.lowlink, w.lowlink) @@ -41,7 +42,7 @@ def strongconnect(self, v, sccs): # Note: The next line may look odd - but is correct. # It says w.index not w.lowlink; that is deliberate and from the original paper v.lowlink = min(v.lowlink, w.index) - + # If v is a root node, pop the stack and generate an SCC if v.lowlink == v.index: # start a new strongly connected component @@ -54,4 +55,3 @@ def strongconnect(self, v, sccs): break scc.sort() sccs.append(scc) - diff --git a/algorithms/strings/multiply_strings.py b/algorithms/strings/multiply_strings.py index 0ddc3abf4..2cb0d2206 100644 --- a/algorithms/strings/multiply_strings.py +++ b/algorithms/strings/multiply_strings.py @@ -12,8 +12,7 @@ """ -def multiply(num1:"str", num2:"str")->"str": - carry = 1 +def multiply(num1: "str", num2: "str") -> "str": interm = [] zero = ord('0') i_pos = 1