Reputation:
I need to fill a list of lists with zeros up to a certain range. I am calculating the reduced profits for a period of infection (a_x). After the infection the profits have to be accounted for with zeros for all of my 3 systems. The planning horizon is 50 years, so I need to extend the elements in my list of lists (tilde_Pi_) to comprise of 50 elements in every sublist respectively.
# Parameters needed for the calculation
year = np.arange(50)
a_x = list(np.arange(5))
Y_ = [2, 8, 12]
C_ = [620, 2000, 4000]
p = 500
r = 0.03
RC_ = [1000, 5000, 10000]
m_ = [50, 30, 15]
ARC_ = [((RC_[i] * r) / (1 - (1+r) ** (-m_[i]))) for i in range(0, 3)]
# Relevant calculation
tilde_Y_ = [[(Y_[i] * 0.8 ** a_x[a]) for a in a_x] for i in range(0, 3)]
tilde_C_ = [[(C_[i] * 0.8 ** a_x[a]) for a in a_x] for i in range(0, 3)]
tilde_Pi_ = [[((p * tilde_Y_[i][a]) - tilde_C_[i][a] - ARC_[i])
for a in a_x] for i in range(0, 3)]
I tried to write an .extend syntax but something is wrong
tilde_Pi_ = [tilde_Pi_[i].extend([0] * (len(year) - len(tilde_Pi_[i])))
for i in range(0, 3)]
Does anyone have an idea how to extend the 3 lists in my list of lists (tilde_Pi_) to comprise of 50 elements respectively, the first 5 (len(a_x)) calculated as above, the remainder filled by zeros?
Upvotes: 0
Views: 1712
Reputation: 990
Try it this way:
for i in range(0, 3):
tilde_Pi_[i].extend([0] * (len(year) - len(tilde_Pi_[i])))
The way to extend sublist is listname[index].extend(new_element)
Hope this helps!
Upvotes: 2