题目描述请点击查看LeetCode 题目描述
Python3 代码解答如下:
import re
class Solution:
def cc(self,a,b):
if len(a) < len(b):
d = a
a = b
b = d
c = []
if len(b) == 0:
c = a
else:
for i in a:
for j in b:
c.append(i+j)
return c
def letterCombinations(self, digits):
"""
:type digits: str
:rtype: List[str]
"""
item = {
'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']
}
result = []
for i in range(0, len(digits)):
result = self.cc(result, item[digits[i]])
print(result)
return result