In this program, we will take a string as input and check whether the string is a subset of another string or not.
Steps to solve the program
- Take a string and a substring as input.
- Convert the input string to a set using set() and assign it to the string3 variable.
- Create a count variable and assign its value equal to 0.
- Use for loop to iterate over string3, if a character from string3 exists in the substring then add 1 to the count variable every time.
- If the value of count variable is equal to the length of the substring then print True else False.
#Input strings
string1 = "iamlearningpythonatsqatools"
string2 = "pystlmi"
string3 = set(string1)
count = 0
for char in string3:
if char in string2:
count += 1
#Printing output
if count == len(string2):
print(True)
else:
print(False)
Output :
True