python也没有很方便- from itertools import combinations
- with open('a.txt', 'r') as f:
- a = f.readlines()
- for i in combinations(range(len(a[0].strip())), 4):
- n = ''.join([a[0][j] for j in i])
- with open(n + '.txt', 'w') as f:
- f.writelines(map(lambda x: ''.join([x[j] for j in i]) + '\n', a))
复制代码 拼回来- import os
- import re
- a = {}
- for i in os.listdir('.'):
- if re.match(r'\d+\.txt', i):
- with open(i, 'r') as f:
- t = f.readlines()
- for j in range(len(t[0].strip())):
- if i[j] in a:
- continue
- a[i[j]] = list(map(lambda x: x[j], t))
- k = sorted([i for i in a.keys()])
- with open('b.txt', 'w') as f:
- f.writelines(map(lambda y:''.join(y) + '\n', zip(*map(lambda x:a[x], k))))
复制代码
|