import itertools
def save(address,listtotal):
with open(address,'w') as f:
i=len(listtotal)
n=0
for content in listtotal:
f.write(str(content)+'\n')
n=n+1
print('正在写入磁盘,请稍后,进度%d%%'%(n/i*100))
print("写入完毕,请查看字典")
#@numba.vectorize(nopython=True)
def load(address1,address2):
list1 = []
list2 = []
m=''
n=''
print('正在合并')
with open(address1,'r') as f:
for line in f:
list1.append(str(line).strip())
with open(address2,'r') as f:
for line in f:
list2.append(str(line).strip())
listtotal=[m+n for m in list1 for n in list2]
return(listtotal)
def dic_make(option,region):
print("生成字典中。。。。。。。。。。")
listtotal=[]
if option=='num':
listtotal=list(range(int(region[0]),int(region[1])+1))
if option=='letters':
list_letters=[]
letters=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','u','p','q','r','s','t','o','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
for n in range(int(region[0]),int(region[1])+1):
list_letters.append(list(itertools.combinations(letters,n)))
for n in range(0,len(list_letters)):
#print(list_letters)
listtotal=listtotal+list_letters[n]
return(listtotal)
if __name__=='__main__':
address=[]
listtotal=[]
region=[]
options=input("请选择生成字典或是组合字典,'m'生成,'c'组合,按回车:")
address_str=input("请依次输入输出文件、待组合字典1、待组合字典2的绝对路径,用','隔开")
address=address_str.split(',')
print(address)
if options=='m':
num_or_letter=input("生成纯数字字典请输入'num',生成英文字典请输入'letters',回车")
region_str=input("请输入文字位数,例如'2,8'表示2至8位的排列")
region=region_str.split(',')
print(region)
listtotal=dic_make(num_or_letter,region)
save(address[0],listtotal)
if options=='c':
listtotal=load(address[1],address[2])
save(address[0], listtotal)