masters1 = "Saito has a very beautiful hand"
ans = ['Saito is','hand','do']
I want to separate masters1 with the words contained in ans and output ['','very beautiful','','is']What I tried
masters1 = "Saito has a very beautiful hand" ans = ['Saito is','hand','do'] for a in ans: masters2 = masters1.split (a) print (masters2) --- #Output result ['Saito has a very beautiful hand','I have']
In this way, it doesn't work because there is a break only in the last'and'.
Please teach someone.
Answer # 1
When the program expands the loop and replaces the variables with literals,
masters2 = "Saito has a very beautiful hand" .split ('Saito is') masters2 = "Saito has a very beautiful hand" .split ('hand') masters2 = "Saito has a very beautiful hand" .split ('and') print (masters2)
That's the result.
If you say "separate by one of these", you will use a regular expression.
import re masters1 = "Saito has a very beautiful hand" ans = ['Saito is','hand','do'] masters2 = re.split ("|" .join (ans), masters1) print (masters2)
- i don't understand the exercises using python trigonometric functions
- python 3x - i want to get the nth array with an argument using python3 argparse
- python - i'm using selenium the text sent by send_keys to the input tag disappears when the text is sent by send_key to the next
- python - yolo i want to detect only a specific class
- please explain the function using the python dictionary
- parameter estimation using python's weighted least squares method (wls)
- parallel processing using python multiprocessingpool and multiprocessingqueue does not work well
- about external libraries when using multiple versions of python
- python 3x - i want to replace a specific sentence end expression with an arbitrary character string
- python - image recognition using cnn keras multiple inputs
- about batch change of file name using python
- (python) how do i split a string into "words in a list"?
- python - updating a specific column in each row does not work in the case of duplicate index in dataframe
- python 3x - how to rename a folder created using jupyternotebook
- python 3x - display a specific string in a text file
- python 3x - processing to jump to the link destination using chrome driver in python
- python - error in image binarization using cv2adaptivethreshold function
- i want to adjust the execution result using the while statement in python as expected
- python - i want to put the image file path in a variable and open it using that variable