Answer:
Explanation:
The python code for the question is attached in the image below.
The objective here is to write a code in python with a function called has_duplicates that takes a string parameter and returns True if the string has any repeated characters. Otherwise, it should return False.
SEE BELOW FOR THE CODE.
alphabet = "abcdefghijklmnopqrstuvwxyz"
test_dups = ["zzz","dog","bookkeeper","subdermatoglyphic","subdermatoglyphics"]
test_miss = ["zzz","subdermatoglyphic","the quick brown fox jumps over the lazy dog"]
def histogram(s):
d = dict()
for c in s:
if c not in d:
d[c]=1
else:
d[c] += 1
return d
def has_duplicates():
for string in test_dups:
dictionary=histogram(string)
duplicates=False
for ch in dictionary.keys():
if dictionary[ch] > 1:
duplicates=True
break
if duplicates==True:
print(string,"has duplicates")
else:
print(string,"has no duplicates")
def missing_letters(string):
answer=""
for ch in alphabet:
if ch not in string:
answer=answer+ch
return answer
print("__________________________________________")
print(" Calling has_duplicates() function")
print("__________________________________________")
has_duplicates()
print("\n______________________________________________")
print("Calling missing_letters() function in for loop")
print("______________________________________________")
for i in test_miss:
answer=missing_letters(i)
if len(answer)>=1:
print(i,"is missing letters",answer)
else:
print(i,"uses all the letters")