Let me paraphase:
out1 = 1 if any bin from Bin 1 to Bin 11 appears in onList, otherwiise out1 = 0
out2 = 1 if any bin from Bin 12 to Bin 15 is in onList, otherwiise out2 = 0
print out1 and out2
is that correct? If so, that is not what your code does.
To start with, your code only prints if onList is not empty. You have a comment that says this is the normal condition, so normally there will be no printing.
Another problem is that your logic for setting out1 or out2 to zero is wrong. You start out great, doing this:
out1 = 0
out2 = 0
But then you screw it up here:
if(i) <= 10:
out1 = 1
else: # (i) > 10
out1 = 0
If onList = ["Bin 2", "Bin 12"], out1 will be set to 1 when your program tests "Bin 2" and it is set to 0 when your program tests "Bin 12". I would expect out1 == 1 (for Bin 2) and out2 == 1 (for Bin 12). Your test was inadequate, checking only one scenario. You should test if the code worked for an empty onList, and write tests for all the boundary conditions.
Your code is not Pythonic. In Python, if your program uses array indexing it usually means the solution is not efficient. Looping in Python is one of the least efficient things you can do. When you are looping, almost all the code is executing in the Python interpreter. This is relatively slow because not only is your program executing the code you wrote, but it is executing an interpreter to execute the code you wrote. Your programs will be much faster (as well as shorter) if you let the Python classes do most of your work. When you use the built in classes (and standard libraries), much of the code execution happens in C libraries. This can be thousands of times faster than running similar code in Python. The built in classes and standard libaries are also highly optimized, so even if they are running some Python code in the interpreter, they will do it more efficiently than code that you or I would write.
If I was writing this code I would avoid the loop and use slices and sets. My program would split the bin list into zones. From your example, zone 1 contains Bin 1 to Bin 11, and zone 2 contains Bin 12 to Bin 15. To determine if a bin in zone 1 is on, I check the interesection of bins in zone 1 and bins in the onList. This is done most efficiently using sets.
A set is an unordered list that supports set operations (intersection, union, difference, complement). To determine if any bin on zone 1 is in the on list, I check if the intersection of zone1 and onList is not empty.
onList = {"Bin 2", "Bin 12"} # This is a set literal
zone1 = {"Bin 1", "Bin 2", "Bin 3"}
intersection = onList & zone1
value = int(bool(intersection)) # bool(intersection) is False for empty set, else True. int(True) == 1, int(False) == 0
print(intersection, value)
Output:
{'Bin 2'} 1
Here is your code (I think) using slices and sets.
bins = [f"Bin {i}" for i in range(1, 16)]
zones = [set(bins[:11]), set(bins[11:])]
def zoneRefresh(on_bins):
"""Return 0 or 1 for each zone. The zone is 1 if any bin
in that zone is in the on list, else zero.
"""
on_bins = set(on_bins)
return [int(bool(zone & on_bins)) for zone in zones]
def test(on_bins):
print(f"{on_bins} = {zoneRefresh(on_bins)}")
test([])
test(["Bin 11"])
test(["Bin 12"])
test(["Bin 5", "Bin 11"])
test(["Bin 5", "Bin 12"])
test(["Bin 11", "Bin 15"])
test(["Bin 12", "Bin 15"])
I added some tests cases to verify it works correctly.
Output:
[] = [0, 0]
['Bin 11'] = [1, 0]
['Bin 12'] = [0, 1]
['Bin 5', 'Bin 11'] = [1, 0]
['Bin 5', 'Bin 12'] = [1, 1]
['Bin 11', 'Bin 15'] = [1, 1]
['Bin 12', 'Bin 15'] = [0, 1]
The update function creates a set and does set operation. This is far fewer operations than you performed in your program, and each of the operations in my program will be performed in compiled C code, not in interpreted Python. My code is also more flexible. If I wanted three zones instead of two, the only change I need to make is where the zones list is constructed.
zones = [set(bins[:6]), set(bins[6:11]), set(bins[11:])] # Make three zones.
[] = [0, 0, 0]
['Bin 11'] = [0, 1, 0]
['Bin 12'] = [0, 0, 1]
['Bin 5', 'Bin 11'] = [1, 1, 0]
['Bin 5', 'Bin 12'] = [1, 0, 1]
['Bin 11', 'Bin 15'] = [0, 1, 1]
['Bin 12', 'Bin 15'] = [0, 0, 1]