+ 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

12th Jun 2020, 10:23 PM
Tomiwa Joseph
Tomiwa Joseph - avatar
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())
12th Jun 2020, 10:45 PM
HonFu
HonFu - avatar
0
Thanks guys.
13th Jun 2020, 8:24 AM
Tomiwa Joseph
Tomiwa Joseph - avatar