Use map:
L = [10, 8, 4, 4, 13, 1, 1, 1, 1, 6, 1, 2, 1, 1, 0, 1, 5, 1, 5, 5, 2, 1, 0, 0, 4]
print map(int, map(bool, L))
Booleans are subclasses of integers, thus False == 0
and True == 1
. Calling int()
on a bool will return either one or zero for true or false, respectively.
Note that in Python 3, map returns an iterator. So you should call list()
on the outside map()