我有一个数字列表,像这样:
7072624 through 7072631
7072672 through 7072687
7072752 through 7072759
7072768 through 7072783
以下是我目前的代码,我已经删除了单词“through”,现在它会打印一个数字列表。
import os
def file_read(fname):
content_array = []
with open (fname) as f:
for line in f:
content_array.append(line)
#print(content_array[33])
#new_content_array = [word for line in content_array[33:175] for word in line.split()]
new_content_array = [word for line in content_array[33:37] for word in line.split()]
while 'through' in new_content_array: new_content_array.remove('through')
print(new_content_array)
file_read('numbersfile.txt')
这会给我以下输出结果。
['7072624', '7072631', '7072672', '7072687', '7072752', '7072759', '7072768', '7072783']
所以我想要做的事情,但很难找到的是如何将'new_content_array'分成两个数组,使输出如下。
array1 = [7072624, 7072672, 7072752, 7072768]
array2 = [7072631, 7072687, 7072759, 7072783]
我希望能够从数组1中取出数组2中的每个值
7072631 - 7072624
7072687 - 7072672
7072759 - 7072752
7072783 - 7072768
我已经搜索过,但没有找到类似于我的情况。
提前致谢!
print (l[::2],l[1::2])
。 - Jongware