I have some code in python, that bitwise or-equals b to all the values in an a multidimensional list called a
for i in xrange(len(a)):
for j in xrange(len(a[i])):
a[i][j] |= b
My question is, is there any way to write this code using only (map(), filter(), reduce()) without having to use lambdas or any other function definitions like in the example below
map(lambda x: map(lambda y: y | b, x), a)
I see absolutely no reason why one should ever avoid lambdas or list comprehensions, but here goes:
import operator,functools
a = map(functools.partial(map, functools.partial(operator.or_, b)), a)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With