Python Practice › String Programs › Program 56
Is one string a subset of another?
Write a Python program to check whether all characters of one string appear in another.
Input
"iamlearningpythonatsqatools", "pystlmi"
Output
True
Approach
- Compare character sets with
<=.
Solution
big = "iamlearningpythonatsqatools"small = "pystlmi"print(set(small) <= set(big))Output
True
Line by line
Line 3
<= on sets means “is a subset of”.
Learn the concept
New to this topic? Read the lesson, then come back.