From a28706fc66e82db7f6177209aa9979f7fe48f476 Mon Sep 17 00:00:00 2001 From: Kia <kia@special-circumstanc.es> Date: Sun, 16 Aug 2020 18:19:29 -0600 Subject: [PATCH] use sum() properly --- cfg_utils.py | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/cfg_utils.py b/cfg_utils.py index c460856..5f2a14f 100644 --- a/cfg_utils.py +++ b/cfg_utils.py @@ -399,13 +399,13 @@ class CFGBoltzmann: print(possible_RHSes) assert(possible_RHSes != []) - sum = 0 + retlist = [] for rhs_index in range(len(possible_RHSes)): print(rhs_index) - sum += self.Fprim(nonterminal_index, rhs_index, 0, exact_length_total) # we index arrays starting at zero. like everyone else. + retlist.append(sum(self.Fprim(nonterminal_index, rhs_index, 0, exact_length_total))) # we index arrays starting at zero. like everyone else. - return sum + return retlist @@ -439,28 +439,23 @@ class CFGBoltzmann: else: # CASE B reduct = self.Fprim(nonterminal_index, which_RHS, how_far_into_the_RHS + 1, exact_length_total - 1) - sum = 0 - for x in reduct: - sum += x - return [sum] + return [sum(reduct)] else: assert (xijk in self.nonterminals) print("xijk", xijk, "is a NONterminal!") print("lenghts of RHS In question is", len(RHS_in_question)) + + # we now calculate the index of nonterminal at index K, we need it for both cases + new_nonterminal_index = self.nonterminals_ordered.index(xijk) + print("NEW NONTERMINAL INDDEX IS", new_nonterminal_index) + if (how_far_into_the_RHS == (len(RHS_in_question) - 1)): # CASE C - # we now calculate the index of nonterminal at index K - - new_nonterminal_index = self.nonterminals_ordered.index(xijk) - print("NEW NONTERMINAL INDDEX IS", new_nonterminal_index) reduct = self.Fzero(new_nonterminal_index, exact_length_total) - sum = 0 - for x in reduct: - sum += x - return [sum] + return [sum(reduct)] else: # CASE D -- GitLab