You can use operator.and_
which essentially performs bitwise and
operation, which is generally done by &
:
>>> from operator import and_
>>> list(map(and_, [1, 0, 0], [1, 1, 0]))
[1, 0, 0]
Generally list comprehension
should be preferred. As with map
it is only useful when you have a builtin function, which in this case can obtained from operator
, but even then, map
approach has to perform another explicit list
call, which would be slightly slower, furthermore even with builtin function list comprehension and map are almost identical in performance. Add that to the fact that list comprehension is generally more verbose. So unless you have a requirement to use functional approach, it is better to stick to list comprehension
.