Skip to content

Commit 264ecca

Browse files
authored
Update find_common_elements_in_list.py
1 parent 06ce0ab commit 264ecca

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

find_common_elements_in_list.py

+9
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,12 @@ def common_elements(list1, list2):
3333
list_c2 = [6, 7, 8, 9, 10, 11]
3434
print(common_elements(list_c1,list_c2))
3535
# common_elements(list_b1, list_b2) should return [] (an empty list).
36+
37+
38+
OR
39+
40+
#Short one using comprehension
41+
def common_elements(list1, list2):
42+
return [element for element in list1 if element in list2]
43+
44+
print(common_elements(list_a1, list_a2))

0 commit comments

Comments
 (0)