I have a piece of my code where I\'m supposed to create a switchboard. I want to return a list of all the switches that are on. Here \"on\" will equal True and
True
Using element-wise multiplication and a set:
>>> states = [False, False, False, False, True, True, False, True, False, False, False, False, False, False, False, False] >>> set(multiply(states,range(1,len(states)+1))-1).difference({-1})
Output: {4, 5, 7}
{4, 5, 7}