String is a subset of another string or not

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
  1. Take a string and a substring as input.
  2. Convert the input string to a set using set() and assign it to the string3 variable.
  3. Create a count variable and assign its value equal to 0.
  4. 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.
  5. 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
				
			

find duplicate characters in a string

sort a string

Leave a Comment