0
need help with replacing words(solved)
i got text with format b'*' where * is random word i need to remove b' ' and left only word (problem i cant remove b without touching other b in words like blob) https://code.sololearn.com/cLTXEA7BUi9x/?ref=app
7 Réponses
+ 2
so, you could do:
q = [s[2:-1] for s in b]
;P
+ 1
# with regular expression, it's quite easy:
import re
p = re.compile("b'([^']*)'")
r = lambda m: m.group(1)
b = ['b\'blob\'','b\'cloud\'']
q = [re.sub(p,r,s) for s in b]
print(*q)
+ 1
i just do that
b=['b\'blob\'','b\'cloud\'']
for i in b:
i=i[1:]
i=i.replace('\'','')
print(i)
+ 1
my solution works also for all b'*' formats in a string with anything before or after, such as:
b = ['start b\'blob\' other b\'cloud\' end']
;)
0
i just find solution by myself but still thanks
0
thanks but my code only output list of words
0
👌 actually yes,thank you!