Skip to content

Commit f5b08e2

Browse files
committed
implement optimization using list comprehension. set() function as stretch
1 parent 43a5216 commit f5b08e2

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

names/names.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# if name_1 == name_2:
1919
# duplicates.append(name_1)
2020

21-
duplicates = set(names_2).intersection(names_1)
21+
# duplicates = [ name for name in names_1 if name in names_2]
2222

2323
end_time = time.time()
2424
print (f"{len(duplicates)} duplicates:\n\n{', '.join(duplicates)}\n\n")
@@ -28,3 +28,5 @@
2828
# Python has built-in tools that allow for a very efficient approach to this problem
2929
# What's the best time you can accomplish? Thare are no restrictions on techniques or data
3030
# structures, but you may not import any additional libraries that you did not write yourself.
31+
32+
duplicates = set(names_2).intersection(names_1)

0 commit comments

Comments
 (0)