Question

Exercise 11.4. If you did Exercise 10.7, you already have a function named has_duplicates that takes a list as a parameter an

Python 3. Help please. Here is my current code. What can I do to fix it? I

list=[1,2,2,3,4,5]
d = {}
for item in list:
if item in d:
return True
d[item] = True
return False

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def has_duplicate(list):
    d = {}
    for item in list:
        if item in d:
            return True
        d[item] = True
    return False


print(has_duplicate([1, 2, 2, 3, 4, 5]))
print(has_duplicate([1, 2, 3, 4, 5, 4]))
print(has_duplicate([1, 2, 3, 4, 5]))

True True False Process finished with exit code 0

Add a comment
Know the answer?
Add Answer to:
Python 3. Help please. Here is my current code. What can I do to fix it?...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Can someone fix this python program? I'm trying to do three things: Create a function that...

    Can someone fix this python program? I'm trying to do three things: Create a function that takes in a string as a parameter. Then create a dictionary of characters to integers, where the integer represents how many times the number of times the character appears in the word. Create a function that takes two lists as parameters and returns the elements they have in common of the two lists. Ask the user to create a list of numbers and keep...

  • Could anyone help add to my python code? I now need to calculate the mean and...

    Could anyone help add to my python code? I now need to calculate the mean and median. In this programming assignment you are to extend the program you wrote for Number Stats to determine the median and mode of the numbers read from the file. You are to create a program called numstat2.py that reads a series of integer numbers from a file and determines and displays the following: The name of the file. The sum of the numbers. The...

  • Hey all, I am writng some code nad this is what I have so far, I...

    Hey all, I am writng some code nad this is what I have so far, I am stuck -Write a function named "write_list" that takes a list of strings as a parameter and writes the contents of the list to a file named "stranger.txt" with one value per line. If a file named "stranger.txt" already exists it must be overwritten. The function should not return any value def write_list(lst): with open ("stranger.txt","w") as file: for string in lst: file.write(string+'\n') write_list(lst)

  • Can someone help me with the main class of my code. Here is the assignment notes....

    Can someone help me with the main class of my code. Here is the assignment notes. Implement project assignment �1� at the end of chapter 18 on page 545 in the textbook. Use the definition shown below for the "jumpSearch" method of the SkipSearch class. Notice that the method is delcared static. Therefore, you do not need to create a new instance of the object before the method is called. Simply use "SkipSearch.jumpSearch(...)" with the appropriate 4 parameter values. When...

  • this is a python question please help me with this code thank you and appreciate it...

    this is a python question please help me with this code thank you and appreciate it 1. Write a Boolean function between that takes two My Time objects, t1 and t2, as arguments, and returns True if the invoking object falls between the two times. Assume t1 <= t2, and make the test closed at the lower bound and open at the upper bound, i.e. return True if t1 <= obj <t2. 2. Turn the above function into a method...

  • python please 11 def add_item(items, word): 14 15 16 F # check if the word is...

    python please 11 def add_item(items, word): 14 15 16 F # check if the word is in the dictionary (keys of dictionary) if word in items: items [word] = items (word] + 1 # update the count else: # word is not in dictionary items[word] = 1 # add the word with count 1 return items [word] # return the current count of word after updation Create a function named build_dictionary that takes a list of words (as a parameter)...

  • hello, please help me to answers my python subjects, I'm new students. I highly appreciate your...

    hello, please help me to answers my python subjects, I'm new students. I highly appreciate your effort. thanks in advanced.. Kindly answers all of this please, I'm begging... 1.) Knowing that a function named fun() resides in a module named mod, choose the proper way to import it:    a.) from mod import fun    b.) from fun import mod    c.) import fun    d.) import fun from mod 2.) Knowing that a function named fun() resides in a...

  • I need help Writing a Python code!!! Implement an ordered list using doubly linked list Implement...

    I need help Writing a Python code!!! Implement an ordered list using doubly linked list Implement the following operations for an ordered list of integers ordered in ascending order using a doubly linked list. The “head” of the list be where the “smallest items are and let “tail” be where the largest items are. You may use whatever mechanism you like to keep track of the head and tail of the list. E.g. references or sentinel nodes. • OrderedList ()...

  • Java Homework Help. Can someone please fix my code and have my program compile correctly? Thanks...

    Java Homework Help. Can someone please fix my code and have my program compile correctly? Thanks for the help. Specifications: The class should have an int field named monthNumber that holds the number of the month. For example, January would be 1, February would be 2, and so forth. In addition, provide the following methods. A no- arg constructor that sets the monthNumber field to 1. A constructor that accepts the number of the month as an argument. It should...

  • A) Please implement a Python script to define a student class with the following attributes (instance...

    A) Please implement a Python script to define a student class with the following attributes (instance attributes): cwid: student’s CWID first_name : student’s first name last_name: student’s last name gender: student’s gender gpa: student’s gpa Please make these attributes as private ones so they have to be accessed via getter/setter methods or property. For this purpose, please define a getter/setter method and property for each of the attributes. Another thing you need to do is to define a constructor that...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT