a splitting headache

jhermann Juergen.Hermann at 1und1.de
Mon Oct 26 11:36:35 CET 2009


On 16 Okt., 02:18, Mensanator <mensana... at aol.com> 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.

Back to the OP's problem, the obvious (if you know the std lib) and
easy solution is:

>>> c = '001010111100101'
>>> filter(None, re.split("(1+)", c))
['00', '1', '0', '1', '0', '1111', '00', '1', '0', '1']

In production code, you compile the regex once, of course.



More information about the Python-list mailing list