Python Practice › Set Programs › Program 27

Union of several sets

EasySet Programs · 27 of 48

Write a Python program to find the union of several sets.

Advertisement
Input
{1, 2}, {2, 3}, {3, 4}
Output
{1, 2, 3, 4}

Approach

  1. set().union(*sets).

Solution

Python
sets = [{1, 2}, {2, 3}, {3, 4}]print(set().union(*sets))
Output
{1, 2, 3, 4}

Learn the concept

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

More set programs

← All 48 Set Programs

Leave a Comment