I have 2 equal-length lists and I am trying to get scalar product of them with, but it does not work this way:
sum(map(lambda a,b: a*b, zip(list1, list2)))
error: TypeError: <lambda>() takes exactly 2 arguments (1 given)
lambda x: (a,b)=x;a*b
well, you don't need a lambda for this...
sum(a*b for a, b in zip(list1, list2))
zip() is slightly less than perfect... to avoid creating a list, either use python3, or
sum(a*b for a, b in itertools.izip(list1, list2))
but if, for some craaaaazy reason, you really really wanted to use lambda, pass each list to map seperately:
sum(map(lambda a, b: a*b, list1, list2))
and even then, you didn't need a lambda either, a callable product is available in the
sum(map(operator.mul, list1, list2))
but use the generator in the first or second example, it will usually be faster.