<jupyter_start><jupyter_text>2020년 10월 6일 화요일 leetCode - Letter Combinations of a Phone Number (Python) 문제 : https://leetcode.com/problems/letter-combinations-of-a-phone-number/ 블로그 : https://somjang.tistory.com/entry/leetCode-17-Letter-Combinations-of-a-Phone-Number-Python  첫번째 시도<jupyter_code>from itertools import combinations

class Solution:
    def letterCombinations(self, digits: str) -> List[str]:
        num2word = {"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']}
        
        if digits == "":
            return []
        else:
            digit_num_list = list(digits)
            
            if len(digit_num_list) == 1:
                return num2word[digit_num_list[0]]
            else:
                word_list = [num2word[digit_num] for digit_num in digit_num_list]
                
                pre_list = word_list[0]
                
                post_lists = word_list[1:]
                
                
                # print("pre_list : {}, post_lists : {}".format(pre_list, post_lists))
                
                for post_list in post_lists:
                    comb_list = self.make_combination_list(pre_list, post_list)
                    
                    pre_list = comb_list
        # print("result : {}".format(comb_list))
                    
        return comb_list
                
                
    @classmethod
    def make_combination_list(self, list1, list2):
        my_comb = []
        
        # print("list1 : {}, list2: {}".format(list1, list2))
        
        
        for word1 in list1:
            for word2 in list2:
                my_comb.append(word1 + word2)
                
        return my_comb<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14453961456102785, 'fraction_numerical': 0.019271948608137045, 'mean_word_length': 1.5922330097087378, 'pattern_counts': {'":': 9, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '239873', 'license': 'MIT', 'n_tokens_mistral': 629, 'n_tokens_neox': 613, 'n_words': 116, 'path': 'DAY 201 ~ 300/DAY229_[leetCode] Letter Combinations of a Phone Number (Python).ipynb', 'repo_name': 'SOMJANG/CODINGTEST_PRACTICE', 'size': '1868'}