I want to be able to remove words I have stored in a list from a string.
currently my code is as follows:
old_string = "BANK TRANSACTION NUM1204012 JOHN"
remove_list = ['BANK TRASACTION', 'PAYMENT TO', 'PAYMENT FROM', 'BANK FEE']
for x in range(len(remove_list)):
new_string = old_string.replace(remove_list[x], "")
This method didn't change anything in the strings
The old string will also be changing every time in a different for loop, I am trying to remove the unnecessary words from bank statements in order to have them presented neater.
I want to be able to keep the number and the name, but remove the rest
I would for example like: new_string = NUM1204012 JOHN
I have also tried using regex
new_string = re.sub(remove_list[x], '', old_string)
but this method removed every instance of a character in remove_list
question from:
https://stackoverflow.com/questions/65829037/how-do-i-remove-words-from-a-list-from-a-string 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…