In this program, we will take a string as input and check if the substring is in string or not.
Steps to solve the program
- Take a string and substring as input.
- Convert them into two different lists using split() and create a count variable and assign its length equal to 0.
- Use for loop to check whether a word from the substring is in the given string.
- If yes, then add 1 to the count variable each time.
- In the end, if the value of the count variable is equal to the length of the list containing the substring print yes else print no.
#Input strings
str1 = "I live in Pune"
str2 = "I live"
list1 = str1.split(" ")
list2 = str2.split(" ")
count = 0
for word in list2:
if word in list1:
count += 1
#Printing output
if count == len(list2):
print("Yes")
else:
print("No")
Output :
Yes