Answer to Question #197992 in Python for FORTUNE AIDOO

Question #197992

 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. 

Write a loop over the strings in list test_miss and call missing_letters with each string. Print a line for each string listing the missing letters.

QUESTION NOT COMPLETE BUT TO BE CONTINUED...

1
Expert's answer
2021-05-24T16:53:12-0400
alphabet = 'abcdefghijklmnopqrstuvwxyz'


test_miss = ["aaa", "abcdddefrr"]
test_dups = ["aabbcc", "abcdd"]


def histogram(s):
    hist = []
    for i in alphabet:
        if not((i in s) or (i.upper() in s)):
            hist.append(i)
    return hist


def has_dups(ss):
    t = set()
    test = True
    for i in ss: t.add(i)
    for i in t:
        if ss.count(i)>1:
            test = False
            print(f"There are (is) {ss.count(i)-1} duplicate(s) of {i}")
    if test:
        print("There are not duplicates in this string")
            


def missing_letters(foo):
    ans = histogram(foo)
    ans.sort()
    ans = ''.join(ans)
    if len(ans)==0:
        print("It uses all the letters")
    else:
        print(ans)


for i in test_dups:
    print("###Calling the function test_dups###")
    has_dups(i)
    print()


for i in test_miss:
    print("###Calling the function test_miss###")
    missing_letters(i)
    print()
    

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS