-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVowel_Spellchecker.py
More file actions
34 lines (30 loc) · 943 Bytes
/
Vowel_Spellchecker.py
File metadata and controls
34 lines (30 loc) · 943 Bytes
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
'''problem : Vowel SpellChecker '''
#CODE :
class Solution:
def spellchecker(self, wordlist, queries):
"""
:type wordlist: List[str]
:type queries: List[str]
:rtype: List[str]
"""
vowels = set(['a', 'e', 'i', 'o', 'u'])
def todev(word):
return "".join('*' if c.lower() in vowels else c.lower()
for c in word)
words = set(wordlist)
caps = {}
vows = {}
for word in wordlist:
caps.setdefault(word.lower(), word)
vows.setdefault(todev(word), word)
def check(query):
if query in words:
return query
lower = query.lower()
if lower in caps:
return caps[lower]
devow = todev(lower)
if devow in vows:
return vows[devow]
return ""
return map(check, queries)