Write a function called missing_letters that takes a string parameter and returns a new string with all the letters of the alphabet that are not in the argument string. The letters in the returned string should be in alphabetical order.
Your implementation should use a histogram from the histogram function. It should also use the global variable alphabet. It should use this global variable directly, not through an argument or a local copy. It should loop over the letters in alphabet to determine which are missing from the input parameter.
The function missing_letters should combine the list of missing letters into a string and return that string.
letters = 'abcdefghijklmnopqrstuvwxyz'
missing = ["aaa", "abcdddefrr"]
duplicate = ["aabbcc", "abcdd"]
def histogram(s):
H = []
for x in letters:
if not((x in s) or (x.upper() in s)):
H.append(x)
return H
def Hd(ss):
t = set()
test = True
for x in ss: t.add(x)
for x in t:
if ss.count(x)>1:
test = False
print(f"There is {ss.count(x)-1} duplicate of {x}")
if test:
print("There are not duplicates in this string")
def missing_letters(foo):
answer = histogram(foo)
answer.sort()
answer = ''.join(answer)
if len(answer)==0:
print("It uses all the letters")
else:
print(answer)
for x in duplicate:
Hd(x)
print()
for x in missing:
missing_letters(x)
print()
Comments
Leave a comment