splitting a string into 2 new strings
Anton Vredegoor
anton at vredegoor.doge.nl
Wed Jul 2 13:00:18 EDT 2003
"Mark Light" <light at soton.ac.uk> wrote:
> I have a string e.g. 'C6 H12 O6' that I wish to split up to give 2
>strings
>'C H O' and '6 12 6'. I have played with string.split() and the re module -
>but can't quite get there.
The issue seems to be resolved already, but I haven't seen the split
and strip combination:
from string import letters,digits
def mysplit(s):
L = [(x.strip(digits) ,x.strip(letters)) for x in s.split()]
return [ ' '.join(x) for x in zip(*L)]
Anton
More information about the Python-list
mailing list