2009/10/26 jhermann <juergen.herm...@1und1.de>: > On 16 Okt., 02:18, Mensanator <mensana...@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. > -- > http://mail.python.org/mailman/listinfo/python-list >
Maybe one can even forget the split function here entirely >>> re.findall(r"0+|1+", '001010111100101') ['00', '1', '0', '1', '0', '1111', '00', '1', '0', '1'] >>> vbr -- http://mail.python.org/mailman/listinfo/python-list