def shortestCompletingWord(licensePlate, words): """ :type licensePlate: str :type words: List[str] :rtype: str """ d = {} licensePlate = licensePlate.lower() for c in licensePlate: if c.isalpha(): d[c] = d.get(c, 0) + 1 res1 = '' res2 = '' length1 = length2 = 20 for word in words: n = len(word) all_in, flag = f(n, word, d) if all_in and n < length1: res1 = word length1 = n if flag and n < length2: res2 = word length2 = n if res1: return res1 return res2