0

Im trying to find the best way to split strings, they could be 2 or 3 characters long depending on the number, E.G. splitting 2r to 2 and r and 10y to 10 and y.

Any help would be greatly appreciated, thanks

Masha
  • 19
  • 3
  • 2
    Please read the following documentation, then edit and rephrase the question. [Take the Tour](https://stackoverflow.com/tour) & [How to ask a good question](https://stackoverflow.com/help/how-to-ask) & [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) & [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users). – Trenton McKinney Jun 14 '20 at 20:25
  • what have you tried and where have you had an issue? – Umar.H Jun 14 '20 at 20:25
  • What I have had an issue with is if the number is 2 digits long a new splitting method needs to be used as I cant just split on the second character for a reliable split – Masha Jun 14 '20 at 20:32
  • This was my answer before it got closed: `digits = ''.join([x for x in string if x.isdigit()]) text = ''.join([x for x in string if not x.isdigit()])` for single strings or `digits = [''.join([x for x in string if x.isdigit()]) for string in list_of_string] text = [''.join([x for x in string if not x.isdigit()]) for string in list_of_string]` for lists of strings – Celius Stingher Jun 14 '20 at 20:35

0 Answers0