想象一下布尔值的列表,它们都是真的:
bools = [True] * 100
然后,我有一个元组,它对应于我要设置为False的bool的索引:
false_index = (0,2,4)
for element in false_index:
bools[element] = False
下次我想用相同的元组设置FALSE元素时,FALSE_INDEX的索引需要考虑已经翻转的列表的False
个值.
我想要一个函数,它接受已翻转的值和要翻转的新值的索引,并返回要翻转的真值的元组,如下所示:
old_false_index = (0,2,4)
new_false_index = (0,2,4)
check_index(old_false_index, new_false_index) # output (1,5,7)
一个更直观的例子: 有关8个True值的列表,请执行以下操作:
[
1
1
1
1
1
1
1
1
]
第一个元组在给定的索引处将元素更改为False.因此,对于(0,2,4),列表现在已更改为:
[
1 # index 0
1
1 # index 2
1
1 # index 4
1
1
1
]
下一次使用相同的元组更改索引时,索引已更改:
[
0
1 # index 1 but the first element that can be changed
0
1
0
1 # index 5 but the third element that can be changed
1
1 # index 7 but the fourth element that can be changed
]