Advertisement
bounslay

Untitled

Mar 27th, 2023
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.50 KB | None | 0 0
  1.  
  2. title = list(input())
  3.  
  4. # Takes user input for the number of words to search for
  5. n = int(input())
  6.  
  7. # Takes user input for each word to search for and stores them in a list
  8. words = [input() for _ in range(n)]
  9.  
  10. # Iterates through each word in the list of words
  11. for word in words:
  12.     # Creates a temporary list of characters that is a copy of the original title
  13.     tempora = list(title)
  14.    
  15.     # Creates a list of indices starting with 0
  16.     indices = [0]
  17.    
  18.     # Iterates through each character in the word
  19.     for l in word:
  20.         # Checks if the character is in the section of tempora starting at the last index in indices
  21.         if l in tempora[indices[-1]:]:
  22.             # Finds the index of the character in tempora
  23.             indo = tempora[indices[-1]:].index(l)
  24.             # Replaces the character in tempora with an empty string
  25.             tempora[indo + indices[-1]] = ""
  26.             # Appends the index of the character to indices
  27.             indices.append(indo + indices[-1])
  28.    
  29.     # If all characters in the word have been found in the title
  30.     if len(indices[1:]) == len(word):
  31.         # Updates the title with the characters that were not removed from tempora
  32.         title = [t for t in tempora if t != ""]
  33.         # Prints the updated title
  34.         print("".join(title))
  35.     # If not all characters in the word have been found in the title
  36.     else:
  37.         # Prints a message indicating that the word cannot be found in the title
  38.         print("No such title found!")
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement