Question #282535

Start with the following Python code.


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


Copy the code above into your program but write all the other code


1
Expert's answer
2021-12-25T01:47:38-0500
def histogram(s):
d = dict()
forc in s:
ifc not in d:
d[c] = 1
else:
d[c] += 1


returnd


def has_duplicates(s):
d=histogram(s)
fori in d.values():
ifi!=1:
returnTrue
returnFalse


def missing_letters(s):
missing_letters_string=""
d=histogram(s)
forch in alphabet:
ifch not in d.keys():
missing_letters_strings+=ch
returnmissing_letters_string


fors in test_dups:
ifhas_duplicates(s):
print(s+"has duplicates")
else:
print(s+"has no duplicates")
print("\n")


fors in test_miss:
missing_letters_string=missing_letters(s)
ifmissing_letters_string!="":
pring(s+" is missing letters "+missing_letters_string)
else:
print(s+" uses all the letters")
print("\n")

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!
LATEST TUTORIALS
APPROVED BY CLIENTS