a splitting headache

Mel mwilson at the-wire.com
Thu Oct 15 21:30:06 EDT 2009


Mensanator wrote:

> All I wanted to do is split a binary number into two lists,
> a list of blocks of consecutive ones and another list of
> blocks of consecutive zeroes.
> 
> But no, you can't do that.
> 
>>>> c = '0010000110'
>>>> c.split('0')
> ['', '', '1', '', '', '', '11', '']
[ ... ]
> OTOH, if my digits were seperated by whitespace, I could use
> str.split(), which behaves differently

Hmm.  You could.

Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) 
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> c = '0010000110'
>>> c1 = c.replace ('01', '0 1')
>>> c1 = c1.replace ('10', '1 0')
>>> c1.split()
['00', '1', '0000', '11', '0']


	Mel.





More information about the Python-list mailing list