From ea757047563f508523fba26b535328eb35d6b8b9 Mon Sep 17 00:00:00 2001 From: Sarey Hamarneh Date: Thu, 4 May 2017 18:58:34 -0400 Subject: [PATCH] Push changes, done --- bpfin/lib/other.py | 17 ++++------------- bpfin/tests/testdata/sample_data.py | 8 ++++---- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/bpfin/lib/other.py b/bpfin/lib/other.py index 075ef93..6c08367 100644 --- a/bpfin/lib/other.py +++ b/bpfin/lib/other.py @@ -3,23 +3,14 @@ import calendar import numpy as np from scipy.optimize import linprog - def add_year_dictionary(dict_1, dict_2): - summed_dictionary = {} - for year_1, item_1 in dict_1.items(): - for year_2, item_2 in dict_2.items(): - if year_1 == year_2: - summed_dictionary[year_1] = item_1 + item_2 - return summed_dictionary + summed_dict = {x: dict_1.get(x, 0) + dict_2.get(x, 0) for x in set(dict_1).union(dict_2)} + return summed_dict def subtract_year_dictionary(dict_1, dict_2): - summed_dictionary = {} - for year_1, item_1 in dict_1.items(): - for year_2, item_2 in dict_2.items(): - if year_1 == year_2: - summed_dictionary[year_1] = item_1 - item_2 - return summed_dictionary + summed_dict = {x: dict_1.get(x, 0) - dict_2.get(x, 0) for x in set(dict_1).union(dict_2)} + return summed_dict def add_list(obj_list, number): diff --git a/bpfin/tests/testdata/sample_data.py b/bpfin/tests/testdata/sample_data.py index a187a3c..5be9768 100644 --- a/bpfin/tests/testdata/sample_data.py +++ b/bpfin/tests/testdata/sample_data.py @@ -285,13 +285,13 @@ raw_income_input = { } } -dict_year_1 = {2012: 500, 2013: 1000, 2014: 2000} +dict_year_1 = {2012: 500, 2013: 1000, 2014: 2000, 2015: 200} -dict_year_2 = {2012: 200, 2013: 3000, 2014: 1000} +dict_year_2 = {2011: 100, 2012: 200, 2013: 3000, 2014: 1000} -dict_add = {2012: 700, 2013: 4000, 2014: 3000} +dict_add = {2011: 100, 2012: 700, 2013: 4000, 2014: 3000, 2015: 200} -dict_sub = {2012: 300, 2013: -2000, 2014: 1000} +dict_sub = {2011: -100, 2012: 300, 2013: -2000, 2014: 1000, 2015: 200} income_statement_full = { 2014: { -- GitLab