I have a list of booleans. I also have a list of start and end indices. In my list of booleans, I want each value to be True
unless it lies in one of the slices defined in the list of indices. What I have written feels very clunky, any suggestions for making it nicer?
bools = [True] * 15
events = [(3, 5), (11, 16)]
for e in events:
bools[e[0]:e[1]] = [False for x in range(*e)]
specifically, I don't like the [False for x in range(*e)]
part. If I start messing around with the slices, the range(*e)
starts to get messy, e.g.:
bools[e[0]:e[1]+2] = [False for x in range(e[0], e[1]+2)]
What would be really nice is if there were a syntax to make every value in a list/slice take the same value, e.g.
bools[e[0]:e[1]+2] = False
But this, obviously, is not correct syntax. Any ideas?