Question
alphabet = abcdefghijklmnopqrstuvwxyz test_dups = [zzz,dog,bookkeeper,subdermatoglyphic,subdermatoglyphics] test_miss = [zzz,subdermatoglyphic,the quick brown fox jumps over the lazy dog] # From Section 11.2 of: # Downey, A.
alphabet = "abcdefghijklmnopqrstuvwxyz"
test_dups = ["zzz","dog","bookkeeper","subdermatoglyphic","subdermatoglyphics"]
test_miss = ["zzz","subdermatoglyphic","the quick brown fox jumps over the lazy dog"]
# From Section 11.2 of:
# Downey, A. (2015). Think Python: How to think like a computer scientist. Needham, Massachusetts: Green Tree Press.
def histogram(s):
d = dict()
for c in s:
if c not in d:
d[c] = 1
else:
d[c] += 1
return d
def duplicates_test(string):
dict = histogram(string)
for key, value in dict.items():
if value > 1:
return True
return False
def miss_test(str):
missingletters = []
dict = histogram(str)
for l in alphabet:
if l not in dict:
missingletters.append(l)
missingletters.sort()
return "".join(missingLettersList)
print("Checking for the duplicate letters")
for str in test_dups:
if duplicates_test(str):
print(str+": has duplicates")
else:
print(str+": has no duplicates")
print(" Checking for the missing_letters ")
for i in test_miss:
string = missing_letters(i.replace(" ",""))
if string!="":
print(lTm+" is missing letters "+string)
else:
print(lTm +" uses all the letters")
Output:
Checking for the duplicate letters zzz: has duplicates dog: has no duplicates bookkeeper: has duplicates subdermatoglyphic: has no duplicates subdermatoglyphics: has duplicates
Checking for the missing_letters Traceback (most recent call last): File "c:\Users\blank\OneDrive\Desktop\For college\Assignment in Unit 7 Prog.py", line 45, in
PLEASE HELP ME FIX IT. WHEN I TRIED TO RUN THE PROGRAM, I GOT AN ERROR.
WHAT CODE SHOULD I PUT IN TO FIX IT?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started