Last active
August 20, 2020 04:09
-
-
Save ellisandrews/f4c39526e0333bae6660210a3dd5a148 to your computer and use it in GitHub Desktop.
Polynomial time complexity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Any, List, Set | |
def find_duplicates(list_: List[Any]) -> Set[Any]: | |
"""Find all duplicate items in a list.""" | |
# Initialize a set to hold the duplicate items | |
duplicates = set() | |
# Check each item in the list against every other item in the list | |
for index_1, item_1 in enumerate(list_): | |
for index_2, item_2 in enumerate(list_): | |
if index_1 != index_2 and item_1 == item_2: | |
duplicates.add(item_1) | |
# Return the set of duplicate items | |
return duplicates |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment