The above "simple replacement does almost the right thing but
1st: it gives n results for n positions
result of above code is:
['0', '1', '0', '0', '0', '0', '0', '0']
['0', '1', '0', '1', '0', '0', '0', '0']
['0', '1', '0', '1', '0', '1', '0', '0']
and 2nd:
it prints out a list not a string!
I would need to have a single result string like this:
"01010100"
User Profile
Collapse
Profile Sidebar
Collapse
DRKT
Last Activity: Jun 13 '16, 03:18 PM
Joined: Jun 6 '16
Location:
-
-
Convert a list "of positions" into a string
Hello everybody,
I managed to convert a string of a given lenght consisting of 2 numbers only (0 and 1) into a list of positions of the number '1', (see example below).
Note: The string size is always going to be a multiple of 4!
Example for string lenght equals 8:
>>> string = "01010100"
>>> [i for i in range(len(strin g)) if string.startswi th('1', i)]
[1, 3, 5]...
No activity results to display
Show More
Leave a comment: