You are on page 1of 2

Part 1

#Code
alphabet = "abcdefghijklmnopqrstuvwxyz"
test_dups = ["zzz","dog","bookkeeper","subdermatoglyphic","subdermatoglyphics"]
def histogram(s):
d = dict()
for c in s:
if c not in d:
d[c] = 1
else:
d[c] += 1
return d
def has_duplicates(s):
for val in histogram(s).values():
return True
return False
for str_1 in test_dups:
if has_duplicates(str_1):
print(str_1, "has duplicates")
else:
print(str_1, "has no duplicates")

Output:

zzz has duplicates


dog has no duplicates
bookkeeper has no duplicates
subdermatoglyphic has no duplicates
subdermatoglyphics has duplicates
>>>

Part 2
#Code

alphabet = "abcdefghijklmnopqrstuvwxyz"
test_miss = ["zzz","subdermatoglyphic","the quick brown fox jumps over the lazy
dog"]
def histogram(s):
d = dict()
for c in s:
if c not in d:
d[c] = 1
else:
d[c] += 1
return d
def missing_letters(str_2):
missings = [] #Empty list
dict_2 = histogram(str_2)
for missing in alphabet:
if missing not in dict_2:
missings.append(missing)
missings.sort()
return "".join(missings)
for miss_let in test_miss:
str_3 = missing_letters(miss_let.replace(" ",""))
if str_3 != "":
print(miss_let, "is missing letters", str_3)
else:
print(miss_let,"uses all the letters")

Output

zzz is missing letters abcdefghijklmnopqrstuvwxy


subdermatoglyphic is missing letters fjknqvwxz
the quick brown fox jumps over the lazy dog uses all the letters
>>>

You might also like