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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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.
Transcribed Image Text:- 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.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education