· 8 years ago · Apr 09, 2018, 11:44 PM
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3"""
4Created on Thu Mar 22 15:39:44 2018
5
6@author: worksheet
7"""
8from itertools import combinations
9
10def emails_with_n_dots(string, n):
11 s = string
12 placements = [x for x in combinations(range(len(s)+n-2), r=n)]
13 valid = []
14 for order in placements:
15 bad = False
16 for index in order:
17 if index+1 in order:
18 bad = True
19 break
20 if not bad:
21 valid.append(order)
22 emails = []
23 for order in valid:
24 email = list(s)
25 [email.insert(i+1, '.') for i in order]
26 if email[-1] != '.':
27 emails.append(''.join(email) + '@gmail.com')
28 return emails
29
30if __name__=='__main__':
31 s = 'roryjhynes'
32 with open('emails.txt', 'w') as f:
33 for n in range(1, 5):
34 f.write('\n')
35 emails = emails_with_n_dots(s,n)
36 f.write('\n'.join(emails))