我想像这样反转列表中的所有布尔值:
a=[True,False,True]
对此:
b=[False,True,False]
我试过
not a
但这对我来说只是虚假的。
您可以使用列表理解和not
所有项目
a=[True,False,True]
b=[not c for c in a]
not a
由于它检查列表为空,因此提供False,因为它没有返回True,所以将其转换为false
a=[True]
not a
False
a=[False]
not a
True
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句