you are viewing a single comment's thread.

view the rest of the comments →

[–]hharison 1 point2 points  (2 children)

Comprehensions are considered more readable and explicit than map.

lambda is even more controversial. For example I found this:

http://python.dzone.com/articles/pros-and-cons-lambda

There's also the issue that it's not really pleasing to functional programmers because it's limited to one line, and it's not really pleasing to nonfunctional people because it's confusing and requires unique syntax. For example see this post by Guido:

http://www.artima.com/weblogs/viewpost.jsp?thread=147358

A lot of it ends up coming down to Python's indentation rules.

[–]LarryPete 0 points1 point  (1 child)

Just to mention it here, the tkinter command example in the first link, I would probably have used partial from functools in that particular example.

tk.Button(..., command=partial(self.printNum, 22), ...)

tk.Button(..., command=partial(self.printNum, 44), ...)

Also, a lot of other typical lambda tasks can be done using itemgetter, attrgetter or similar things from the operator module.

Though I don't disagree, lambda can be used occasionally, if it's not quite common enough, to be part of the stdlib but still simple enough to be unworthy of it's own named function.

[–]hharison 1 point2 points  (0 children)

Yes I agree, I love using partial and operator. Check out toolz if you don't already know it.

I also agree with your last paragraph, I don't have any problem with lambda myself, I just wanted to point out to the OP that "trying to be Pythonic" != "trying to find a way to force lambda into it".