a splitting headache

Mensanator mensanator at aol.com
Mon Oct 26 18:52:09 EDT 2009


On Oct 26, 7:28 am, Vlastimil Brom <vlastimil.b... at gmail.com> wrote:
> 2009/10/26 jhermann <Juergen.Herm... at 1und1.de>:
>
>
>
>
>
> > 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.
> > --
> >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']
>

Very good. Thanks to both of you. Now if I could only remember
why I wanted to do this.

>
>
> vbr




More information about the Python-list mailing list