Python Practice › Set Programs › Program 12

List to a set

EasySet Programs · 12 of 48

Write a Python program to convert a list to a set.

Advertisement
Input
[4, 2, 4, 9, 2]
Output
{9, 2, 4}

Approach

  1. set(list) removes duplicates.

Solution

Python
print(set([4, 2, 4, 9, 2]))
Output
{9, 2, 4}

Learn the concept

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

More set programs

← All 48 Set Programs

Leave a Comment