求解关于数字1~66中,以数字1开头的九位不重复排列组合,用空格符号隔开 竖向输出。

. 1.因排列组合结果较多,程序设置手动点击方式运行,点击运行一次,程序输出排列组合结果100万组/次。
2.每次排列组合结果均新建一个属性为:xlsx 的Excel文档,保存。
3.D2 D3 D4以下单元格显示编号:1 2 3 .…,E2 E3 E4以下单元格显示排列组合:1 2 3 4 5 6 7 8 9 / 1 2 3 4 5 6 7 8 10 / 1 2 3 4 5 6 7 8 11 ……输出第一次运行前100万组排列组合结果,然后保存

讨论数量: 1
Jason990420

Following code took five and a half hours to write the result to a large TXT file which is more than 100GB !

from time import time
from itertools import combinations

upper   = 66
qty     =  9
lst     = list(range(2, upper+1))

start   = time()

with open("numbers.txt", "wt") as f:
    for items in combinations(lst, qty-1):
        f.write(' '.join(('1',) + tuple(map(str, items))) + '\n')

stop = time()
print(stop - start)
19651.745468854904
5个月前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!