- #1
FallenApple
- 566
- 61
Here is the code. I have binary list of ones and zeros and I want to see the values of the consequtive ones. For example, 111=3 and 11=2
So I created a count loop and increment the count when A is not 0. Then I tried to update the count to 0 once the for loop got to 0 again, but for some reason, the count doesn't update anymore.
The output is
[0, 0, 3, 0] code is in bold.]
Mod note: Added code tags.
So I created a count loop and increment the count when A is not 0. Then I tried to update the count to 0 once the for loop got to 0 again, but for some reason, the count doesn't update anymore.
The output is
[0, 0, 3, 0] code is in bold.]
Mod note: Added code tags.
Python:
A=[0,1,1,1,0,0,1,1] #list of binary numbers(0 and 1s)
count=0 # count to keep track of a particular grouping of ones.
countList=[0] # A list to keep track of all the different counts
for i in range (0, len(A)-1):
if A!=0:
count=count+1
else:
countList.append(count)
count=0 # resetting the count since i hit value of 0.
print(countList)
Last edited by a moderator: