apply
will take its second argument (which should be a tuple/list) and passes each element of this tuple as positional argument to the object you passed to apply
as first argument.
That means if x = [1,2,3]
and you call
apply(lambda x: x * 2, (x))
apply
will call the lambda function with the arguments 1
, 2
, and 3
, which will fail, since the lambda function only takes a single argument.
To have it work, you should but x
into a tuple or a list:
print apply(lambda x: x * 2, [x])
or
# note the extra ','. (x,) is a tuple; (x) is not.
# this is probably the source of your confusion.
print apply(lambda x: x * 2, (x,))