Python Practice › Set Programs › Program 30
Common elements
Write a Python program to find the elements common to two sets of words.
Input
{"python", "java", "sql"}, {"sql", "python", "go"}Output
['python', 'sql']
Approach
&, thensortedfor display.
Solution
a = {"python", "java", "sql"}b = {"sql", "python", "go"}print(sorted(a & b))Output
['python', 'sql']
Learn the concept
New to this topic? Read the lesson, then come back.