所以以下代码读取两个文本文件,每个文件都包含25行25个整数,并将它们分别放入两个列表中:
num_DIR = '/path/to/num.txt'
den_DIR = '/path/to/den.txt'
def makeList(DIR):
list = []
for line in open(DIR).readlines():
list.append(line.strip())
return list
num_list = makeList(num_DIR)
den_list = makeList(den_DIR)
输出:
num_list = ['76539', '100441', '108637', '108874', '103580', '91869', '78458', '61955', '46100', '32701', '21111', '13577', '7747', '4455', '2309', '1192', '554', '264', '134', '63', '28', '15', '12', '7', '5']
den_list = ['621266', '496647', '436229', '394595', '353249', '305882', '253983', '199455', '147380', '102872', '67255', '41934', '24506', '13778', '7179', '3646', '1778', '816', '436', '217', '114', '74', '49', '44', '26']
我该如何将两个列表中的每个值都变成其后所有值的累加和,就像一个累加列表一样?
['1','2','3']
->['6','5','3']
? - martineau