我有一个列表,它被附加在不同文件(file_1,file_2,..)的循环中。我用零开始列表,因为我需要创建一个以1开头的范围: / p>
a = [0] #here is the zero value created
a = [0, 8] #here is the list after open file 1
a = [0, 8, 20] #here is the list after open file 2
a = [0, 8, 20, 23] #here is the list after open file 3
....
我需要创建一个范围(我的输出):
file_1 = 1 - 8
file_2 = 9 - 28 #basically, ('the previous last element + 1' - 'the sum of the list')
file_3 = 29 - 51
...
感谢您的帮助。
答案 0 :(得分:1)
这个怎么样:
range(sum(a[:-1]), sum(a))
答案 1 :(得分:0)
我不完全确定你对“文件1”“文件2”等的含义。我想你的意思是有一个名为file 1的文件?
files = ['file 1', 'file 2', 'file 3']
a = [0, 8, 20, 23]
for i in range(len(a) - 1):
print('{} = {} - {}'.format(files[i], a[i] + 1, a[i + 1]))