0

For example, I want to take a weirdly formatted expression: '4.2+5 - 6' and return this list: ['4.2', '+', '5', '-', '6]

I can return ['4.2', '5', '6'] but I don't know where to go from there.

DonnyFlaw
  • 581
  • 3
  • 9
  • Show your current code – DonnyFlaw Feb 17 '21 at 15:43
  • 2
    Does this answer your question? [In Python, how do I split a string and keep the separators?](https://stackoverflow.com/questions/2136556/in-python-how-do-i-split-a-string-and-keep-the-separators) In your case: `re.split('([+-])', '4.2+5 - 6')` – 001 Feb 17 '21 at 15:44
  • You should provide a description of what input you are expecting. You just provided one example. Make sure to include all edge cases! – Klaus D. Feb 17 '21 at 15:45
  • It's hard to answer with a single example. Does this work for you? `\d+(\.\d+)?|\+|\-` – D Hudson Feb 17 '21 at 17:30

0 Answers0