python——字典生成工具

环境:python 3.6.7

简单的字典生成工具

# -*- coding: utf-8 -*-

f = open("F:\\dict.txt", 'w')	#字典文件的存储路径,以写方式打开
chars = [						#字典中字符的组合,可以根据需要进行更改
	'0','1','2','3','4','5','6','7','8','9',
	'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',
	'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',
]

base = len(chars)		#字符集的长度
end = len(chars) ** 4	#若是 4 位字符,则共有 len(chars) ** 4 中组合方式

for i in range(0, end):
	n = i
	
	ch0 = chars[n % base]
	n=n//base
	ch1=chars[n % base]
	n=n//base
	ch2=chars[n % base]
	n=n//base
	ch3=chars[n % base]
    
	f.write(ch3 + ch2 + ch1 + ch0 + '\n')	#把生成的字典写入字典文件中
	print(i, ch3, ch2, ch1, ch0)			#在页面中打印字典

f.close()

猜你喜欢

转载自blog.csdn.net/weixin_43915762/article/details/88085389