a splitting headache
- From: Mensanator <mensanator@xxxxxxx>
- Date: Thu, 15 Oct 2009 18:18:09 -0700 (PDT)
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', '']c = '0010000110'
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', '', '', '', '']f = ' 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']' 1 11 111 11 '.split()
That means I can use re to solve my problem after all.
['1', '11']c = '0010000110'
['00', '0000', '0']re.sub('1',' ',c).split()
Would it have been that difficult to show in the documentation
how to do this?
- Prev by Date: Raw_input with readline in a daemon thread makes terminal text disappear
- Next by Date: How about adding slice notation to iterators/generators?
- Previous by thread: Raw_input with readline in a daemon thread makes terminal text disappear
- Next by thread: Re: a splitting headache