-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphonenum.py2
45 lines (40 loc) · 943 Bytes
/
phonenum.py2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/python2
from sys import argv
#import timeit
import itertools
data = open(argv[1],'r').read().splitlines()
TR = {\
0:('0'), 1:('1'),
2:('a','b','c'),
3:('d','e','f'),
4:('g','h','i'),
5:('j','k','l'),
6:('m','n','o'),
7:('p','q','r','s'),
8:('t','u','v'),
9:('w','x','y','z')
}
results=[]
def main(line): #this is looped from input
# line is defined to be a number mapping to the dictionary
# each number in the line is iterated through all possible combos
#print('this is a new shot for ', line)
line = [int(a) for a in list(line)]
out=[]
for num in list(line):
a=[]
for ch in TR[num]:
a.append(ch)
out.append(a)
o = []
for x in (itertools.product(*out)):
o.append(''.join( x ))
o.sort()
results.append(o)
for line in data:
if not line:
continue
main(line)
# timeit.Timer(main(line)).timeit()
for l in results:
print ','.join(l)