I have two string variables - string_A
and string_B
. string_A
contains the following:
"ONE" # "TWO" # "THREE" # "FOUR" # "FIVE"
and string_B
contains:
"NANA" # "PAA" # "THREE" # "ELI"
I want to remove all the elements that are in string_A
from string_B
. After I print string_B
it should look like "NANA" # "PAA" # "ELI"
Update:
x = textA.split(' # ')
y = textB.split(' # ')
for i, j in enumerate(x):
if j in y[i]:
pass
a = '"ONE" # "TWO" # "THREE" # "FOUR" # "FIVE"'
b = '"NANA" # "PAA" # "THREE" # "ELI"'
a_elements = set(a.split(' # '))
b_elements = [key for key in b.split(' # ') if key not in a_elements]
b = ' # '.join(b_elements)
A straight-forward solution:
a = '"ONE" # "TWO" # "THREE" # "FOUR" # "FIVE"'
b = '"NANA" # "PAA" # "THREE" # "ELI'
a_elements = [key.strip() for key in a.split('#')]
b_elements = [key.strip() for key in b.split('#')]
filtered_b_elements = [key for key in b_elements if key not in a_elements]
new_b = ' # '.join(filtered_b_elements)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With