-
Notifications
You must be signed in to change notification settings - Fork 0
/
17.py
39 lines (32 loc) · 880 Bytes
/
17.py
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
def one(x,y):
res = []
for i in x:
for j in y:
res.append(j+i)
return res
letter = lambda a,b:b if a==[] else a if b==[] else one(a,b)
class Solution(object):
def letterCombinations(self, digits):
"""
:type digits: str
:rtype: List[str]
"""
maplist ={
'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']
}
resu = []
def getCom(i,result):
if i==len(digits):
return result
else:
return getCom(i+1,letter(maplist[digits[i]],result))
return getCom(0,resu)
solu = Solution()
print solu.letterCombinations('23')