"<title>", "</title>"
I want to erase these strings from the a string
If you list it
['<title>i', 'love', 'you', 'so', 'much', 'baby</title>']````
How can I solve this?
a = "<title>i love you so much baby</title>"
a_list = a.split()
b = ["love"]
for idx, value in enumerate(a_list):
if value in b:
a_list[idx] = "_______"
# print (if you see the word love)
# # print(temp)
elif value in a_list:
a_list[idx] = value + " "
# print ("If you can't see the word love")
re = " ".join(a_list)
print(re)
>>> a = "<title>i love you so much baby</title>"
>>> a.replace("<title>", "").replace("</title>", "")
'i love you so much baby'
import re
>>> a = "<title>i love you so much baby</title>"
>>> tag = 'title'
>>> print(re.findall('<%s>(.+)</%s>' % (tag, tag), a))
['i love you so much baby']
I've used regular expressions.
© 2024 OneMinuteCode. All rights reserved.