Python Practice › String Programs › Program 56

Is one string a subset of another?

EasyString Programs · 56 of 106

Write a Python program to check whether all characters of one string appear in another.

Advertisement
Input
"iamlearningpythonatsqatools", "pystlmi"
Output
True

Approach

  1. Compare character sets with <=.

Solution

Python
big = "iamlearningpythonatsqatools"small = "pystlmi"print(set(small) <= set(big))
Output
True

Line by line

Line 3

<= on sets means “is a subset of”.

Advertisement

Learn the concept

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

More string programs

← All 106 String Programs