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]
3 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]3 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
While troubleshooting a connectivity issue in your network, you did a Ping from Host A to Host B, and the Ping was successful. F
xeze [42]

Answer:

Above OSI Layer 3

Explanation:

5 0
3 years ago
How will you maintain electrical tools and equipment?
PSYCHO15rus [73]
Electronic tools should not rub against each other when stored. Keep all the tools in the dry area and protect them from moisture, dust, and direct sunlight. To prevent injuries, keep the sharpen tool in a tool holder.
4 0
3 years ago
Read 2 more answers
public static String[] strArrMethod(String[] arr) { String[] result = new String[arr.length]; for (int j = 0; j < arr.length;
faust18 [17]

Answer:

answer is 24

Explanation:

hope this helps

7 0
3 years ago
I want to find Web pages that deal with the ethical aspects of genetic engineering. I also want to limit my results to education
ankoles [38]

Answer:

"ethical aspects of genetic engineering" AND site:.edu

Explanation:

Google search defines the following operators:

" "  --> search for the exact phrase between <em>quotes</em>.

site: --> search for specific <em>sites </em><em>or domains </em>by adding "site:" in front.

AND --> Limit  results to include both statements joined with <em>AND</em>.

In a generic way:

" <em>exact phrase to search</em> " AND site: <em>domain</em>

In this example:

" ethical aspects of genetic engineering " AND site:.edu

7 0
3 years ago
B. List any four major drawbacks of the first generation computer​
d1i1m1o1n [39]

Answer:

Terribly low storage space, limited to mathematics/computing, required entire rooms to use, and low information yield for hours of processing.

Explanation:

3 0
3 years ago
Other questions:
  • Cloud Kicks is undergoing a GDPR-focused implementation to ensure access to personal information data is limited to only users w
    7·1 answer
  • Given the list my_list containing integers, create a list consisting of all the even elements of my_list. Associate the new list
    12·1 answer
  • A ____ appearing in the main text of a document indicates a footnote or endnote.
    15·1 answer
  • ________ are typically comprised of a mix of ________ and ________.
    5·2 answers
  • Order the following routine maintenance tasks from most to least important when securing a computer. a. Verify anti-malware sett
    15·1 answer
  • WILL GIVE BRAINLIEST
    14·2 answers
  • What is the answer to in Microsoft Word you can access the blank from the command command from the mini toolbar what is the corr
    10·2 answers
  • Write a program that prompts the user for the name of two files each containing a single line that represents a decimal integerc
    11·1 answer
  • Define application software​
    12·1 answer
  • How to print something nad input on same line python
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!