Python: Find common items from two lists
Find Common Items in Lists
Write a Python program to find common items in two lists.
Sample Solution:
Python Code:
# Define a tuple 'color1' containing color names
color1 = "Red", "Green", "Orange", "White"
# Define another tuple 'color2' containing color names
color2 = "Black", "Green", "White", "Pink"
# Create sets from 'color1' and 'color2' to perform set intersection (common elements)
# Print the result, which contains the colors that are common to both sets
print(set(color1) & set(color2))
Sample Output:
{'Green', 'White'}
Flowchart:
Python Code Editor:
Previous: Write a Python program to get variable unique identification number or string.
Next: Write a Python program to change the position of every n-th value with the (n+1)th in a list.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics