>>> import re >>> text = "You think we did this un-thinkingly?" >>> re.split(r'\s|-', text) ['You', 'think', 'we', 'did', 'this', 'un', 'thinkingly?']
As noted by @larsmans, to break into multiple spaces / hyphens (emulating .split() with no arguments), it is used [...] to read:
>>> re.split(r'[\s-]+', text) ['You', 'think', 'we', 'did', 'this', 'un', 'thinkingly?']
Without regex (in this case, regex is the easiest option):
>>> [y for x in text.split() for y in x.split('-')] ['You', 'think', 'we', 'did', 'this', 'un', 'thinkingly?']
Actually @Elazar's answer without regex is also quite simple (I vouch for regex anyway)
source share