import random # 数字库 import string # 字符串库 code=string.digits+string.ascii_letters print(code) # 生成字符串 def getCode(): # sample 取出样本 return ''.join(random.sample(code,4)) print(getCode()) def key(group): return "-".join([getCode() for i in range(group)]) print((key(5)))