Answer to Question #282544 in Python for solokin

Question #282544

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. For example, for the string "aaa", the output should be the following.



aaa is missing letters bcdefghijklmnopqrstuvwxyz



If the string has all the letters in alphabet, the output should say it uses all the letters. For example, the output for the string alphabet itself would be the following.



abcdefghijklmnopqrstuvwxyz uses all the letters



Print a line like one of the above for each of the strings in test_miss.



Submit your Python program. It should include the following.



The provided code for alphabet, test_dups, test_miss, and histogram.


Your implementation of the has_duplicates function.


A loop that outputs duplicate information for each string in test_dups.


Your implementation of the missing_letters function.


A loop that outputs missing letters for each string in test_miss.


1
Expert's answer
2021-12-26T09:42:28-0500
letters = 'abcdefghijklmnopqrstuvwxyz'
test_miss = ["aaa", "abcdddefrr"]
test_dups = ["aabbcc", "abcdd"]

def histogram(s):
    Hi = []
    for x in letters:
        if not((x in s) or (x.upper() in s)):
            Hi.append(x)
    return Hi

def has_dups(y):
    m = set()
    T = True
    for x in y: m.add(x)
    for x in m:
        if y.count(x)>1:
            T = False
            print(f"There are {y.count(x)-1} duplicate of {x}")
    if T:
        print("There are not duplicates in this string")
            
def missing_letters(u):
    answer = histogram(u)
    answer.sort()
    answer = ''.join(answer)
    if len(answer)==0:
        print("It uses all the letters")
    else:
        print(answer)

for x in test_dups:
    has_dups(x)
    print()

for x in test_miss:
    missing_letters(x)
    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