The mistake is in the zip(x,y)
. What the function zip()
makes is, for each element of the list x , joins with the corresponding element at the position of the list y in a tuple and adds it to a list. That is, this function waits as parameters eternal objects, as lists by exeplo.
The function map()
executes a function specified for each item in an iterable. The item is sent to the function as a parameter.
In practice, what you are doing is passing to your function zip()
the values 69
and 1.7526
, that are not eternal, for being whole and float. That’s why the error appears:
Typeerror: 'int' Object is not iterable
That is, an object of the type int
is not eternal.
Breaking the problem by pieces, we have:
def myFunc(x,y):
return (x,y)
>>> print(list(map(myFunc, [69,77,54], [1.7526, 1.9558, 1.3716])))
[(69, 1.7526), (77, 1.9558), (54, 1.3716)]
The idea of using the lambda
is that it enters as the function, so instead of declaring a function myFunc
, can use direct lambda x,y: (x,y)
:
>>> print(list(map(lambda x,y: (x,y), [69,77,54], [1.7526, 1.9558, 1.3716])))
[(69, 1.7526), (77, 1.9558), (54, 1.3716)]
But it is also possible to leave even more automatic:
print(list(map(lambda x: (x, x*0.0254),[69,77,54])))