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
  • 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)...

  • 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...

  • Python Programming: Why do I get UnboundLocalError? What does this mean and how can I fix...

    Python Programming: Why do I get UnboundLocalError? What does this mean and how can I fix it? Question: Write a function check_move(column, row) which returns a string describing a chess move to a given row and column on the chess board. Your program must check if the row and column entered are both valid. The column in a chess board is a letter ranging from A to H or a to h (inclusive) and the row is a number between...

  • PYTHON. Continues off another code. I don't understand this. Someone please help! Comment the lines please...

    PYTHON. Continues off another code. I don't understand this. Someone please help! Comment the lines please so I can understand LinkedList ADT: class myLinkedList:     def __init__(self):         self.__head = None         self.__tail = None         self.__size = 0     def insert(self, i, data):         if self.isEmpty():             self.__head = listNode(data)             self.__tail = self.__head         elif i <= 0:             self.__head = listNode(data, self.__head)         elif i >= self.__size:             self.__tail.setNext(listNode(data))             self.__tail = self.__tail.getNext()         else:             current = self.__getIthNode(i - 1)             current.setNext(listNode(data,...

  • PYTHON. Continues off another code(other code is below). I don't understand this. Someone please help! Comment...

    PYTHON. Continues off another code(other code is below). I don't understand this. Someone please help! Comment the lines please so I can understand. There are short and med files lengths for each the list of names/ids and then search id file. These are the input files: https://codeshare.io/aVQd46 https://codeshare.io/5M3XnR https://codeshare.io/2W684E https://codeshare.io/5RJwZ4 LinkedList ADT to store student records(code is below). Using LinkedList ADT instead of the Python List. You will need to use the Student ADT(code is below) Imports the Student class...

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
ADVERTISEMENT