fork download
  1. import re
  2. rx = re.compile(r"\s*(?:\b(?:and|or)\b|[,.])\s*")
  3. strings = ["make the cake, walk the dog, and pick-up poo.", "flour, egg-whites and sand."]
  4. for s in strings:
  5. print( list(filter(None, rx.split(s))) )
Success #stdin #stdout 0.02s 9384KB
stdin
Standard input is empty
stdout
['make the cake', 'walk the dog', 'pick-up poo']
['flour', 'egg-whites', 'sand']