-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem1.py
24 lines (16 loc) · 1.07 KB
/
problem1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import string
import random
def getMissingLetters(sentence=""): # default argument: empty string --> should return "abcdef...xyz"
alphabet = set(string.ascii_lowercase) # set contains every letter of the alphabet
appears = set() # set will hold unique letters we find in the sentence
for x in sentence:
if x.isalpha(): # first check if x is even a letter
appears.add(x.lower()) # only add lowercase letters to set
if len(appears) == 26: break # check if we've exhausted all possible letters
solution = alphabet - appears # set difference to get letters that don't appear at all in sentence
solution = ''.join(sorted(solution)) # convert solution set to a sorted string
return solution
# Test cases:
print(getMissingLetters("A quick brown fox jumps over the lazy dog"))
print(getMissingLetters())
print(getMissingLetters(''.join(random.choices(string.ascii_letters + string.digits + string.whitespace, k=100000000000))))