Python Practice › Set Programs › Program 30

Common elements

EasySet Programs · 30 of 48

Write a Python program to find the elements common to two sets of words.

Advertisement
Input
{"python", "java", "sql"}, {"sql", "python", "go"}
Output
['python', 'sql']

Approach

  1. &, then sorted for display.

Solution

Python
a = {"python", "java", "sql"}b = {"sql", "python", "go"}print(sorted(a & b))
Output
['python', 'sql']
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More set programs

← All 48 Set Programs