How to convert a list of booleans to ints in Python

Converting a list of booleans to ints converts each boolean in the list into an integer. True converts to 1, and False converts to 0. For example, converting [True, False] returns [1, 0].

Solution for How to convert a list of booleans to ints in Python : You can use map() to convert a list of booleans to ints Use map(function, iterable) with a list of booleans as iterable and int as function to apply int() to each boolean in the list. Use list(iterable) with the output of map() as iterable to convert to a list.


how-to-convert-a-list-of-booleans-to-ints-in-python