标签:letter 随机 不能 set mail ring letters 一个 必须
写一个函数,这个函数的功能是,传入一个数字,产生N条邮箱,产生的手机号不能重复。
邮箱前面的长度是6 - 12
之间,产生的邮箱必须包含大写字母、小写字母、数字和特殊字符
import random
import string
def email2(count):
emails = set()
while len(emails)!=count:
email_len = random.randint(6,12)
email_end = (‘@163.com‘, ‘@qq.com‘, ‘@sina.com‘, ‘@126.com‘)
end = random.choice(email_end)
res = random.sample(string.ascii_letters+string.digits+string.punctuation,email_len)
if set(res) & set(string.ascii_lowercase) and \
set(res) & set(string.ascii_uppercase) and \
set(res) & set(string.digits) and \
set(res) & set(string.punctuation):
email = ‘‘.join(res)+end+‘\n‘
emails.add(email)
with open(‘email.txt‘,‘w‘) as fw:
fw.writelines(emails)
email2(50)
标签:letter 随机 不能 set mail ring letters 一个 必须
原文地址:https://www.cnblogs.com/lily-20141202/p/10055259.html