Python Practice › Set Programs › Program 45

Set of favourite actors

EasySet Programs · 45 of 48

Write a Python program to create a set of your favourite actors.

Advertisement
Output
4 ['Akshay Kumar', 'Robert Pattinson', 'Shah Rukh Khan', 'Tom Hardy']

Approach

  1. A set of strings; print it sorted.

Solution

Python
actors = {"Shah Rukh Khan", "Akshay Kumar", "Tom Hardy", "Robert Pattinson", "Akshay Kumar"}print(len(actors), sorted(actors))
Output
4 ['Akshay Kumar', 'Robert Pattinson', 'Shah Rukh Khan', 'Tom Hardy']

Line by line

Line 1

“Akshay Kumar” appears twice but is stored once.

Learn the concept

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

More set programs

← All 48 Set Programs

Leave a Comment