public
Created

find duplicate

  • Download Gist
find_duplicate.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.