[Tutor] differences between map and partial?

Steven D'Aprano steve at pearwood.info
Tue Sep 27 20:32:49 EDT 2016


Hello Liu An and welcome!


On Tue, Sep 27, 2016 at 05:23:52PM +0800, source liu wrote:

>     this one works >>>>print p.map(partial(file_op,lineop=unity),input)
>     this one doesn't work >>>>print p.map(lambda x:file_op(x,unity), input)

What does "doesn't work" mean?

What is "p.map"?

What are "file_op" and "input"?

It will help if you can provide a minimal example of code that we can 
actually run:

http://sscce.org/

and also state what you expect to happen and what actually happens.


But my *guess* is that if the following two expressions are different:

  partial(file_op, lineop=unity)

  lambda x:file_op(x, unity)


that implies that file_op() takes more than two arguments, and in the 
second case (the lambda) unity is being used for something other than 
lineop. Try to compare these instead:

  partial(file_op, lineop=unity)

  lambda x:file_op(x, lineop=unity)



-- 
Steve


More information about the Tutor mailing list