IIUC, you need to split the string by each of the delimiters, so you could do the following:
symbols = "@, &, %, $".split(', ')
print(symbols) # this is a list
text = "The first @ The second & and here you have % and finally $"
# make a copy of text
replaced = text[:]
# unify delimiters
for symbol in symbols:
replaced = replaced.replace(symbol, '@')
print(replaced) # now the string only have @ in the place of other symbols
for chunk in replaced.split('@'):
if chunk: # avoid printing empty strings
print(chunk)
Output
['@', '&', '%', '$'] # print(symbols)
The first @ The second @ and here you have @ and finally @ # print(replaced)
The first
The second
and here you have
and finally
The first step:
symbols = "@, &, %, $".split(', ')
print(symbols) # this is a list
converts your string to a list. The second step replaces, using replace, all symbols with only one because str.split only works with a single string:
# unify delimiters
for symbol in symbols:
replaced = replaced.replace(symbol, '@')
The third and final step is to split the string by the chosen symbol (i.e @
):
for chunk in replaced.split('@'):
if chunk: # avoid printing empty strings
print(chunk)