For Python 2.7, what is the logic of below lambda expression, confused by this part int(s), it seems no variable called s.
x = [tuple(map(lambda s: int(s), x.split(':'))) for x in y.split(' ')]
thanks in advance, Lin
For Python 2.7, what is the logic of below lambda expression, confused by this part int(s), it seems no variable called s.
x = [tuple(map(lambda s: int(s), x.split(':'))) for x in y.split(' ')]
thanks in advance, Lin
The lambda function was used with map, so the parameters for the lambda are passed from the second argument of map. Understanding how map works will help you understand better how the lambda takes its parameter:
Apply function to every item of
iterableand return a list of the results. If additional iterable arguments are passed, function must take that many arguments and is applied to the items from all iterables in parallel
So s represents each item from the iterable x.split(':') and int(s) implies an explicit cast of item s to integer, where int(x) is the return object of the lambda.