I have to take a list of lists and another list and create a relationship between them. For context, I am not allowed to use pandas or dictionaries or anything like that.
I have opened two files and created two functions, the first function that turns the file with the year and the 12 job creation values assigned to that year making a list of lists. The next file is the name of the presidents and the years they served, for the second function I made the data in that file into a list.
I have to correlate their party and the president's term with the year they served and when I am done with assigning the president with the list of lists, I have to average them.
What I need help doing is somehow merging the lists so that I could have each president with their assigned year and the data for that year in a list. an example of what I need is like:
[James Earl Carter, 1979-1981, Democrat, 140990, 14135, etc...] for all the years he served.
`
Here is an example of both files:
1979,14090,14135,14152,14191,14221,14239,14288,14328,14422,14484,14532,14559
1980,14624,14747,14754,14795,14827,14784,14861,14870,14824,14900,14903,14946
1981,14969,14981,14987,14985,14971,14963,14993,15007,14971,15028,15073,15075
1982,15056,15056,15050,15075,15132,15207,15299,15328,15403,15463,15515,15538
1983,15611,15671,15731,15797,15834,15852,15901,15891,15819,15858,15894,15911
1984,15937,15947,15956,15977,15990,16045,16150,16229,16128,16136,16173,16180
1985,16201,16226,16296,16583,16454,16441,16418,16410,16330,16386,16391,16373
1986,16360,16346,16292,16260,16198,16159,16175,16110,16031,16069,16078,16073
1987,16041,16011,16024,16010,16003,16016,15890,15930,15923,15956,15977,15981
1988,16023,16004,16005,15990,16005,16020,16011,16016,16042,15986,15997,16008
1989,16010,16025,16030,16075,16103,16127,16172,16224,16255,16274,16311,16282
James Earl Carter, 1979-1981, Democrat
Ronald Wilson Reagan, 1981-1989, Republican
And here is the code I have so far:
def avg():
file = open("government_employment_Windows.txt")
my_list = []
for line in file:
line.strip()
line = line.split(',')
line[1] = int(line[1])
line[2] = int(line[2])
line[3] = int(line[3])
line[4] = int(line[4])
line[5] = int(line[5])
line[6] = int(line[6])
line[7] = int(line[7])
line[8] = int(line[8])
line[9] = int(line[9])
line[10] = int(line[10])
line[11] = int(line[11])
line[12] = int(line[12])
my_list.append(line)
file.close()
return my_list
def pres(list_of_lists):
p_file = open("presidents_Windows.txt")
print(list_of_lists)
for line in p_file:
line = line.strip()
line = line.split(',')
line[1] = line[1].strip()
line[2] = line[2].strip()
print(line)
for small_list in list_of_lists:
if line[0] in small_list:
small_list.append(line[0])
print(list_of_lists)
list_of_lists = avg()
pres(list_of_lists)
Final result should look like:
Government employement average per month:
Republican: 18562
Democrat: 19599
Government Employment by President:
First Month Last Month Difference
Carter: 14090 14946
Reagan: 14969 16008
Bush: 16010 17347
Clinton: 17365 19466
Bush: 19450 21546
Obama: 21538 22266
Trump: 22264 21902