import time
from bst import BSTNode

start_time = time.time()

f = open('names_1.txt', 'r')
names_1 = f.read().split("\n")  # List containing 10000 names
f.close()

f = open('names_2.txt', 'r')
names_2 = f.read().split("\n")  # List containing 10000 names
f.close()

duplicates = set(names_1) & set(names_2)  # Return the list of duplicates in this data structure

# Replace the nested for loops below with your improvements
# for name_1 in names_1:
#     for name_2 in names_2:
#         if name_1 == name_2:
#             duplicates.append(name_1)
# bt = BSTNode('names') #binary search tree run time: .061 secs

# for name in names_1:
#     bt.insert(name)
# for name in names_2:
#     if bt.contains(name):
#         duplicates.append(name)

end_time = time.time()
print (f"{len(duplicates)} duplicates:\n\n{', '.join(duplicates)}\n\n")
print (f"runtime: {end_time - start_time} seconds")

# ---------- Stretch Goal -----------
# Python has built-in tools that allow for a very efficient approach to this problem
# What's the best time you can accomplish?  Thare are no restrictions on techniques or data
# structures, but you may not import any additional libraries that you did not write yourself.


# duplicates = list(set(names_1).intersection(names_2)) #.00347 secs stretch
# duplicates = set(names_1) & set(names_2) #.00446 run time 

# & operator means give me the interect between the two list, or alternatively (and it seems to be the faster case) you can just call the intersect method on set(names_1) passing names_2 as the list to check against 