1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Aleks [24]
2 years ago
7

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.

Computers and Technology
1 answer:
vichka [17]2 years ago
3 0

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")

You might be interested in
What year did polaroid introduce one-step photography with the SX-70
blagie [28]

Answer:

I first saw the Polaroid SX-70—the one-step instant camera introduced in 1972 by the company's co-founder, Dr.

Explanation:

5 0
2 years ago
In Microsoft word you can access the ______ command from "mini toolbar"
Mashcka [7]
Redo command, i think.
8 0
3 years ago
Read 2 more answers
After you divide the viewfinder appropriately you locate the subject? PLZ ANSWER MY TEST DO BY TONIGHT
Sloan [31]
The Answer is A: <span>along one of the division lines. </span>
4 0
3 years ago
A(n) _____ is a common output device for hard copy.
Sidana [21]
The answer is d it is d it is d I think I think, I’m not sure though
8 0
3 years ago
What term is used to describe an individual's money and personal property? budget income assets finances
Ilya [14]

Answer:

Pretty sure it's assests.

Explanation:

Income - Intake of money.

Budget - How much money you can spend.

Finances - Things you need to pay ort fund.

3 0
3 years ago
Read 2 more answers
Other questions:
  • Which of the following roles is responsible for writing programming code?
    10·1 answer
  • Refer to the exhibit. the gigabit interfaces on both routers have been configured with subinterface numbers that match the vlan
    11·1 answer
  • Write a program that implement a bubble sort ?
    5·1 answer
  • Why is it important to protect people's intellectual property online?
    10·1 answer
  • No matter what medium connects computers on network-copper wires, fiber-optic cables, or a wireless setup; the same protocol mus
    11·1 answer
  • A local variable that is declared as ____ causes the program to keep the variable and its latest value even when the function th
    10·1 answer
  • Guess The Song: <br> What Popping Brand New Whip Just Hopped In, I Got options
    15·1 answer
  • Write an application that displays the strings in the provided array alphabetically in ascending order.
    9·1 answer
  • Mr. Simmons has assigned a research project. Every student in the class will create a single page report about the recycling hab
    15·1 answer
  • Stock Market
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!