-3

i want to make the boolean list to negated boolean list for example, below code has same meaning

lst= [True, False]
neg_lst = list(map(lambda x: not x, lst))

I think that there are the simplest way to make boolean list to be negated. like, unary operator. maybe.

always thanks for a lot of your help.

Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555
frhyme
  • 966
  • 1
  • 15
  • 24

1 Answers1

1

You can use the not_ function from the operator package:

from operator import not_

map(not_, some_list)

Or you can use list comprehension:

[not x for x in some_list]
Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555