M
Mensanator
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.
['', '', '1', '', '', '', '11', '']
Ok, the consecutive delimiters appear as empty strings for
reasons unknown (except for the first one). Except when they
start or end the string in which case the first one is included.
Maybe there's a reason for this inconsistent behaviour but you
won't find it in the documentation.
And the re module doesn't help.
['', '', '1', '2', '', '3', '', '', '4', '', '', '', '']
OTOH, if my digits were seperated by whitespace, I could use
str.split(), which behaves differently (but not re.split()
because it requires a string argument).
['1', '11', '111', '11']
That means I can use re to solve my problem after all.
Would it have been that difficult to show in the documentation
how to do this?
a list of blocks of consecutive ones and another list of
blocks of consecutive zeroes.
But no, you can't do that.
['', '', '1', '', '', '', '11', '']
Ok, the consecutive delimiters appear as empty strings for
reasons unknown (except for the first one). Except when they
start or end the string in which case the first one is included.
Maybe there's a reason for this inconsistent behaviour but you
won't find it in the documentation.
And the re module doesn't help.
['', '', '1', '2', '', '3', '', '', '4', '', '', '', '']
OTOH, if my digits were seperated by whitespace, I could use
str.split(), which behaves differently (but not re.split()
because it requires a string argument).
['1', '11', '111', '11']
That means I can use re to solve my problem after all.
['00', '0000', '0']c = '0010000110'
re.sub('0',' ',c).split() ['1', '11']
re.sub('1',' ',c).split()
Would it have been that difficult to show in the documentation
how to do this?