splitting a string into 2 new strings
news at yebu.de
Wed Jul 2 14:04:58 CEST 2003
Mark Light schrieb:
> I have a string e.g. 'C6 H12 O6' that I wish to split up to give 2
> 'C H O' and '6 12 6'. I have played with string.split() and the re module -
> but can't quite get there.
> Any help would be greatly appreciated.
Hi Mark aka Sugar-Baby,
there are very likely easier ways, but at least
s = 'C6 H12 O6'
print [' '.join(xx) for xx in apply(
zip,[(x,x[1:]) for x in s.split()])]
gives some results,
More information about the Python-list