写一个函数,这个函数的功能是,传入一个数字,产生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+' ' emails.add(email) with open('email.txt','w') as fw: fw.writelines(emails) email2(50)