Complete the empty function below and check your activity:
In [75]:
def nonogram_sequence(binary_array):
sequence = []
counter = 0
for num in binary_array:
if num == 1:
counter += 1
elif counter != 0:
sequence.append(counter)
counter = 0
if counter:
sequence.append(counter)
return sequence
When you're ready, use the Check Activity button to check your function.
Test the function by yourself..
In [76]:
example_1 = [1, 1, 1, 0, 1, 1]
example_2 = [1, 0, 1, 1, 1, 1]
example_3 = [1, 1, 1, 1, 1, 1]
example_4 = [1, 0, 1, 0, 1, 1]
example_5 = [0, 0, 0, 0, 0, 0]
In [77]:
nonogram_sequence(example_1)
Out[77]:
[3, 2]
In [37]:
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Cell In[37], line 1 ----> 1 example_1.index.list() AttributeError: 'builtin_function_or_method' object has no attribute 'list'
In [19]:
example_1[[0]]
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[19], line 1 ----> 1 example_1[[0]] TypeError: list indices must be integers or slices, not list
In [ ]:
nonogram_sequence(example_2)
In [ ]:
In [ ]:
nonogram_sequence(example_3)
In [ ]:
In [ ]:
nonogram_sequence(example_4)
In [ ]:
In [ ]:
nonogram_sequence(example_5)
In [ ]: