Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- title = list(input())
- # Takes user input for the number of words to search for
- n = int(input())
- # Takes user input for each word to search for and stores them in a list
- words = [input() for _ in range(n)]
- # Iterates through each word in the list of words
- for word in words:
- # Creates a temporary list of characters that is a copy of the original title
- tempora = list(title)
- # Creates a list of indices starting with 0
- indices = [0]
- # Iterates through each character in the word
- for l in word:
- # Checks if the character is in the section of tempora starting at the last index in indices
- if l in tempora[indices[-1]:]:
- # Finds the index of the character in tempora
- indo = tempora[indices[-1]:].index(l)
- # Replaces the character in tempora with an empty string
- tempora[indo + indices[-1]] = ""
- # Appends the index of the character to indices
- indices.append(indo + indices[-1])
- # If all characters in the word have been found in the title
- if len(indices[1:]) == len(word):
- # Updates the title with the characters that were not removed from tempora
- title = [t for t in tempora if t != ""]
- # Prints the updated title
- print("".join(title))
- # If not all characters in the word have been found in the title
- else:
- # Prints a message indicating that the word cannot be found in the title
- print("No such title found!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement