Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
names.py using sets complete in 0.031 seconds
  • Loading branch information
Hunter315 committed Jan 25, 2019
commit c8c6ad6989e4da934b6af8c9916028b14d0a51a6
12 changes: 8 additions & 4 deletions names/names.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@
f.close()

duplicates = []
for name_1 in names_1:
for name_2 in names_2:
if name_1 == name_2:
duplicates.append(name_1)
# for name_1 in names_1:
# for name_2 in names_2:
# if name_1 == name_2:
# duplicates.append(name_1)
a_set = set(names_1)
b_set = set(names_2)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice you can also use intersection or a for loop with an if all of these would be O(n)

if (a_set & b_set):
duplicates.append(repr(a_set & b_set))

end_time = time.time()
print (f"{len(duplicates)} duplicates:\n\n{', '.join(duplicates)}\n\n")
Expand Down
1 change: 1 addition & 0 deletions search/binary_search_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def depth_first_for_each(self, cb):

def breadth_first_for_each(self, cb):
nodes = [self]
#while loop going through every node
while len(nodes) > 0:
current = nodes.pop(0)
cb(current.value)
Expand Down