本帖最后由 aloha20200628 于 2025-3-10 17:23 编辑
回复 1# 思想之翼
也给一个 python 版本
第一题型》生成35个分割文件(存为 test1.py 与 A.txt 源文件同目录运行)- from itertools import combinations
- with open('A.txt', 'r') as fr: all = fr.readlines()
- for l in (list(combinations(range(1,8),4))):
- with open((ln:=''.join([str(i) for i in l]))+'.txt', 'w') as fw:
- for s in all: fw.write(s[int(ln[0])-1]+s[int(ln[1])-1]+s[int(ln[2])-1]+s[int(ln[3])-1]+'\n')
复制代码 第二题型》复原源文件的副本 AA.txt(存为 test2.py 运行,须基于 test1.py 的运行结果-即35个分割文件已经产生)- with open('1234.txt', 'r') as fr: a1 = fr.readlines()
- with open('4567.txt', 'r') as fr: a2 = fr.readlines()
- with open('AA.txt', 'w') as fw:
- for n in range(len(a1)): fw.write(a1[n].strip()+a2[n][1:])
复制代码
|