I’m a beginner at Python and I have a short question which I haven’t been able to find a solution to:
Is there any way to regulate what is overwritten in a list? For instance, I have a list filled with zeros which I will then gradually fill up with other elements, what I want to be able to do is to create an error when something other than a zero is overwritten. Is there any smart way to do this?
Could I use something like:
a = [0, 1, 0, 1, 0, 0, 0, 0]
b = []
[i for i, e in enumerate(a) if e != 0]
return False
or something similar?
You can use a function to change the elements in the list, which checks if the element is
0.And now you can use it by calling
setElement(<list>, <index>, <element>)