Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: using map() without lambdas on a multidimensional array/list

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)
like image 622
weeb Avatar asked Jan 18 '23 07:01

weeb


1 Answers

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)
like image 58
phihag Avatar answered Jan 31 '23 07:01

phihag