What I have:
array = original_array[:]
result = reduce(lambda a,b: some_function(b,array), array)
What I want:
I want to get rid of the array = original_array[:] statement.
Ideally I would simply replace the array parameter inside reduce() with original_array[:], but I need it inside lambda as well. Is there a way to refer to the
array parameter from within lambda?
The following is not an acceptable solution, because it makes a new array copy for every element:
result = reduce(lambda a,b: some_function(b,original_array[:]), original_array[:])
I need something like this:
result = reduce(lambda a,b: some_function(b,reduce_parameter), original_array[:])
You could wrap the whole thing in another lambda:
But your original solution is in my opinion preferable because it’s more readable.