我编写了一个程序,使用一组字符在文件中搜索该集合的任何排列。我很乐意为您优化该计划提出建议。
我将文件分成多个,具体取决于每个“单词”的字符数:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import itertools
import time
start_time = time.time()
chrset = sys.argv[1]
lgr = len(chrset)
f = open('gd'+str(lgr), 'r')
perms = []
s = list(itertools.permutations(chrset))
for perm in s:
perms.append(''.join(map(str,perm)))
for line in f:
line = line.rstrip('\n')
for pp in perms:
if pp == line:
print (line)
print("--- %s seconds ---" % (time.time() - start_time))