+ 4
Split it
Is there a way to split a string with multiple arguments? Eg. a = 'learn#ing tak&es tim!e Can it be split at ['#', '&', '!']? https://code.sololearn.com/cDZfmm3IV0Jn/?ref=app
3 Respostas
+ 6
Hm, no builtin way, I think.
You can loop over your split symbol list and use consecutive replaces, or maybe do some regex magic.
You can do comprehension trickery as well, but... well, that's just another way of replacing stuff I suppose.
s = 'Hello, my dear friend! You ... fine?'
print(''.join(' ' if l in (',!.?') else l for l in s).split())
0
Thanks guys.