Advertisement
Programmin-in-Python

Finding a Sub-String in a Main String (By Matching Positions of Sub-String)

Dec 26th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. def substrinstr(str1, str2):
  2.     T1 = ()
  3.     L1 = list(str2)
  4.  
  5.    
  6.     for i in str1:
  7.         if any(L1):
  8.             if (i.lower() == L1[0]):
  9.                 T1 += (i,)
  10.                 del L1[0]
  11.     else:
  12.         L1 = list(str2)
  13.  
  14.         if T1 == tuple(L1):
  15.             return "The Sub-String is Present in the String..."
  16.         else:
  17.             return "The Sub-String is NOT Present in the String..."
  18.    
  19. str1 = input("Enter the Full String : ")
  20. str2 = input("Enter the Sub-String to be searched for in the String : ")
  21. val = substrinstr(str1, str2)
  22. print(val)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement