Concise python solution

  • 3

    Is this considered pythonic?

     class Solution(object):
      def letterCombinations(self, digits):
        if not digits:
            return []
        results = ['']
        map = {'2':'abc', '3':'def', '4':'ghi', '5':'jkl', '6':'mno', '7':'pqrs', '8':'tuv', '9':'wxyz'}
        for digit in digits:
            results = [result+d for result in results for d in map[digit]]
        return results

  • 0

    I'd say just rename the map dict to something else because map is a keyword. Otherwise looks good.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.