About 80,900 results
Open links in new tab
  1. python - Use 'try/except' instead of 'if' to find duplicates in a list ...

    Jan 5, 2017 · I'm making a program that finds item that are repeated in an array and I did have it working using the if command, but with long arrays the if command slows down the program …

  2. Try/Except in Python: How to avoid duplication?

    Sep 1, 2017 · In this example, the ApiWrapper class converts the low-level ApiException into the nicer ApiWrapperException. But there's a lot of duplication. I can put the duplicated code in an …

  3. How to Find Duplicates in a List – Python | GeeksforGeeks

    Nov 27, 2024 · Removing duplicates from a list is a common operation in Python which is useful in scenarios where unique elements are required. Python provides multiple methods to …

  4. How to raise error if user tries to enter duplicate entries in a set …

    Dec 22, 2016 · If you want to raise an exception on duplicate insertion, you could do something like this: def add(self, value): if value in self: raise DuplicateKeyError('Value {!r} already …

  5. Python Try Except - W3Schools

    Try to open and write to a file that is not writable: The program can continue, without leaving the file object open. As a Python developer you can choose to throw an exception if a condition …

  6. Python Try Except: Examples And Best Practices

    Sep 24, 2024 · In this article, you will learn how to handle errors in Python by using the Python try and except keywords. It will also teach you how to create custom exceptions, which can be …

  7. How to Check for Duplicates in a Python List?

    Feb 10, 2025 · A simple but inefficient way to check for duplicates in a Python list is using nested loops. The first loop selects an item, and the second loop compares it with every other item in …

  8. Check If a List has Duplicate Elements - PythonForBeginners.com

    Sep 2, 2021 · In this article, we will look at different ways to check if a list has duplicate elements in it. We know that sets in Python contain only unique elements. We can use this property of …

  9. 5 Best Ways to Find Duplicate Items in a List in Python

    Mar 3, 2024 · This article explores various methods to find these duplicates efficiently. Method 1: Using a Set for Membership Tests. Set membership in Python is a fast operation, and …

  10. Find Duplicates in a Python List - datagy

    Dec 16, 2021 · How to Find Duplicates in a List in Python. Let’s start this tutorial by covering off how to find duplicates in a list in Python. We can do this by making use of both the set() …

  11. Some results have been removed
Refresh