Advertisement
arealloudbird

problem2

Oct 17th, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. def problem2(w,a,L1,L2):
  4.     if IsStringInL(w,L1) or IsStringInL(w,L2):
  5.         return True
  6.  
  7.     myBool = False
  8.  
  9.     for i in range(0, len(a)):
  10.  
  11.         if (IsStringInL(w[0:a[i]],L1) or IsStringInL(w[0:a[i]],L2)):
  12.  
  13.             myBool = problem2(w[a[i]:len(w)],a,L1,L2)
  14.  
  15.             if myBool == True:
  16.                 return myBool
  17.     return False
  18.  
  19. def IsStringInL(w,L):
  20.     if w in L:
  21.         return True
  22.     return False
  23.  
  24. if __name__=="__main__":
  25.     w = input("Enter a string to test: ")
  26.     a = [5,4,3] # array containing all possible string lengths in L1 and L2
  27.     L1 = ["fish", "foo", "fun", "flip", "fin", "fruit"]
  28.     L2 = ["pop", "pomp", "pump", "puff", "pat", "poot"]
  29.    
  30.     print(problem2(w,a,L1,L2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement