Write 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. Implement has_duplicates by creating a histogram using the histogram function above. Do not use any of the implementations of has_duplicates that are given in your textbook. Instead, your implementation should use the counts in the histogram to decide if there are any duplicates. Write a loop over the strings in the provided test_dups list. Print each string in the list and whether or not it has any duplicates based on the return value of has_duplicates for that string. For example, the output for "aaa" and "abc" would be the following.
Bartleby answered my homework and
Write 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.
Implement has_duplicates by creating a histogram using the histogram function above. Do not use any of the implementations of has_duplicates that are given in your textbook. Instead, your implementation should use the counts in the histogram to decide if there are any duplicates.
Write a loop over the strings in the provided test_dups list. Print each string in the list and whether or not it has any duplicates based on the return value of has_duplicates for that string. For example, the output for "aaa" and "abc" would be the following.
aaa has duplicates
abc has no duplicates
Print a line like one of the above for each of the strings in test_dups.
True needs to be defined. I tried to code it but didn't accept and got an error message.
![- Unit7LearningJournal_has_duplicates.py - F:\CS Programming Fundamentals\Unit 7\Unit7LearningJournal_has_duplicates.py (3.9.5)
File Edit Format Run Options Window Help
lalphabet
= "abcdefghijklmnopqrstuvwxyz"
test dups = ["zzz","dog", "bookkeeper","subdermatoglyphic","subdermatoglyphics"]
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 duplicate (string) :
# return false if each letter in s is not distinct
h=histogram (string)
for k, v in h.items () :
if v>l:
return true
return false
for string in test dups:
if has duplicate (string):
printf(string, "has duplicates")
else:
print (string, "has no duplicates")
def main () :
test dups loop ()
if name-' main
main ()
Ln: 1 Col: 0
10:50 PM
O Search for anything
f
A 4) O
남
99+
W
5/25/2021
8.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F2b3e0ad1-27e4-45d5-9d4c-cf1a19e4c930%2F41f65cf8-b8e2-4229-8e42-7424f52f8b33%2Fvfo0kmk_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)