1str = 'Lorem; ipsum. dolor sit amet, consectetur adipiscing elit.'
2str = str.split(',')
3print(str) # Output ['Lorem; ipsum. dolor sit amet', ' consectetur adipiscing elit.']
4
5import re
6str = 'Lorem; ipsum. dolor sit amet, consectetur adipiscing elit.'
7str = re.split(r';|,|\.', str)
8print(str) # Output ['Lorem', ' ipsum', ' dolor sit amet', ' consectetur adipiscing elit', '']
1>>> a='Beautiful, is; better*than\nugly'
2>>> import re
3>>> re.split('; |, |\*|\n',a)
4['Beautiful', 'is', 'better', 'than', 'ugly']
1>>> a='Beautiful, is; better*than\nugly'
2>>> import re
3>>> re.split('; |, |\*|\n',a)
4['Beautiful', 'is', 'better', 'than', 'ugly']
5
1# using rsplit()
2# Split on last occurrence of delimiter
3res = test_string.rsplit(', ', 1)
1#Do a str.replace('? ', ', ') and then a str.split(', ')
2#Example:
3a = "Hello, what is your name? I'm Bob."
4a.replace('? ', ', ')
5print(a)
6#"Hello, what is your name, I'm Bob."
7a.split(", ")
8print(a)
9#["Hello", "what is your name", "I'm Bob."]