splitting a string into 2 new strings

Karl Scalet news at yebu.de
Wed Jul 2 14:04:58 CEST 2003

Mark Light schrieb:
> Hi,
>       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.
> Any help would be greatly appreciated.
> Thanks,
> Mark.

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[0],x[1:]) for x in s.split()])]

gives some results,


More information about the Python-list mailing list