grains.utils.toggle

grains.utils.toggle(lst)[source]

Return True for False values and False for True values in a list.

Parameters

lst (list) – An arbitrary list, possibly containing other lists.

Returns

list – Element-wise logical not operator applied on the input list.

Notes

Solution taken from https://stackoverflow.com/a/51122372/4892892.

Examples

>>> toggle([True, False])
[False, True]
>>> toggle(['h', 0, 2.3, -2, 5, []])
[False, True, False, False, False, True]