Created
October 26, 2011 10:06
-
-
Save kevinetienne/1315945 to your computer and use it in GitHub Desktop.
find duplicate
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
def find_duplicate(seq): | |
# holds our duplicate list | |
duplicate_bucket = [] | |
# helps to identify a duplicate | |
seen_bucket = set() | |
for item in (seq): | |
if item not in seen_bucket: | |
seen_bucket.add(item) | |
else: | |
duplicate_bucket.append(item) | |
return duplicate_bucket | |
def find_dup(counter, next_element, seen_bucket, bucket): | |
""" | |
recursive function to find duplicate | |
based on a generator | |
""" | |
el = next_element.next().group() | |
if el not in seen_bucket: | |
seen_bucket.add(el) | |
else: | |
bucket.append(el) | |
counter -= 1 | |
if counter > 0: | |
return find_dup(counter, next_element, seen_bucket, bucket) | |
return seen_bucket, bucket |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment