you can do a few things here you can
1. iterate over the list and make groups of numbers as they become available, adding them to the list of results.
not a great solution.
2. Use regular expressions.
implementation 2:
>>> import re >>> s = "123ab4 5" >>> re.findall('\d+|[^\d]', s) ['123', 'a', 'b', '4', ' ', '5']
you want to capture any group that is at least 1 number \d+ or any other character.
change
At first John beat me up to the right decision. and this is a wonderful solution.
I will leave it here because someone else may misunderstand the question and look for the answer to what I thought was written. I was impressed that the OP wanted to capture only groups of numbers and leave everything else individual.
source share