How to Find the Common Elements Between Two Lists in Python

list1 = [1, 2, 3, 4, 5]
list2 = [3, 4, 5, 6, 7]
common_elements = list(set(list1) & set(list2))
print(f"List 1: {list1}\nList 2: {list2}\nCommon Elements: {common_elements}")

Output:

List 1: [1, 2, 3, 4, 5]
List 2: [3, 4, 5, 6, 7]
Common Elements: [3, 4, 5]

Leave a Comment

Your email address will not be published.